How to add column in a gridview dynamically
when I click button, a new column is added to gridview dynamically
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rahul BansalPosted Mar 17, 2015, 12:46 AM
DataTable dt = new DataTable();
dt =//get data from the database in the dt
gridview1.datasource = dt;
gridview1.databind();
then you can add the column in the dt and bind the grid again
dt.Columns.Add("NewColumn");
dt.AcceptChanges();
//Again bind it to the gridview
gridview1.datasource = dt; gridview1.databind();