1

What is the C# code (code behind) for adding a column to grdview in asp.net ...something equivalent to this :

<asp:BoundField DataField="Last Name" 
             HeaderText="Last Name" 
             SortExpression="LastName" />

3 Answers 3

3
BoundField boundfield = new BoundField();
boundfield.DataField = "Last Name";
boundfield.HeaderText = "Last Name";
boundfield.SortExpression= "LastName";
GridView1.Columns.Add(boundfield);
Sign up to request clarification or add additional context in comments.

Comments

1

Something along these lines:

var column = new BoundField();
column.DataField = "LastName";
column.HeaderText = "Last Name";
column.SortExpression = "LastName";
GridView1.Columns.Add(column);

Comments

1
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var boundColumn = new BoundField();
                boundColumn.DataField = "LastName";
                boundColumn.HeaderText = "Last Name";
                boundColumn.SortExpression = "LastName";
                GVPictures.Columns.Add(boundColumn);                
                BindGridView();
            }
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.