Dynamically add column
a textbox contains a value,in save time it filled to the grid not save to table how it posiible
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
Joxin Stanly181 reputationPosted Oct 3, 2013, 3:24 AM EDT
i have pasted a sample code. hope it give you some idea on how to proceed...
public void FillGrid()
{
ViewState["Data"] = null;
DataTable dt = new DataTable();
//Add Columns to the datatable
dt.Columns.Add("Name");
//Define a datarow for the datatable dt
DataRow dr = dt.NewRow();
//Now add the datarow to the datatable
dr["Name"] = Textbox1.Text; //value from textbox on screen
dt.Rows.Add(dr);
ViewState["Data"] = dt;
GridView1.DataSource = dt;
GridView1.Bind();
}
Navaz85 reputationPosted Oct 3, 2013, 3:33 AM EDT
Navaz85 reputationPosted Oct 3, 2013, 3:33 AM EDT
Joxin Stanly181 reputationPosted Oct 3, 2013, 3:39 AM EDT
Prashant Srivastava87 reputationPosted Oct 5, 2013, 4:21 AM EDT
If you are doing that in window application then you have firstly check one thing that -- can any post back occur after grid is bind. If yes, then inspite of declaring the datatable within the FillGrid() menthod declare that DataTable as Public (i.e. globally) so as to avoid lossing of data on postback. It will help you in maintaining the Grid State.