How to add column in a gridview dynamically
when I click button, a new column is added to gridview dynamically
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rahul BansalRank #143 · 15.9K reputationPosted Mar 16, 2015, 8:46 PM EDT
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();