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.
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.
Prashant SrivastavaPosted Oct 5, 2013, 8:21 AM
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.
Joxin StanlyPosted Oct 3, 2013, 7:39 AM
NavazPosted Oct 3, 2013, 7:33 AM
NavazPosted Oct 3, 2013, 7:33 AM
Joxin StanlyPosted Oct 3, 2013, 7:24 AM
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();
}