how to add a new row in a grid at runtime
-
using a grid i have created two rows by binding the hidden template field with a datasource in pageload event, Now i have to Add a new row in the grid using a button click....maitaining the values in the textbox in the grid entered by user.... ========================= /* <%# Eval("ROW") %> */ coding in page_load event is =================================== protected void Page_Load(object sender, EventArgs e) { Addrow(dgLocsch, 2); } private void Addrow(DataGrid dg, int NoOfRows) { DataTable dt = new DataTable(); dt.Columns.Add("ROW"); for (int i = 1; i <= NoOfRows; i++) { DataRow dr; dr = dt.NewRow(); dr["ROW"] = i.ToString(); dt.Rows.Add(dr); } dg.DataSource = dt; dg.DataBind(); } can any one help me......
thank u
-
using a grid i have created two rows by binding the hidden template field with a datasource in pageload event, Now i have to Add a new row in the grid using a button click....maitaining the values in the textbox in the grid entered by user.... ========================= /* <%# Eval("ROW") %> */ coding in page_load event is =================================== protected void Page_Load(object sender, EventArgs e) { Addrow(dgLocsch, 2); } private void Addrow(DataGrid dg, int NoOfRows) { DataTable dt = new DataTable(); dt.Columns.Add("ROW"); for (int i = 1; i <= NoOfRows; i++) { DataRow dr; dr = dt.NewRow(); dr["ROW"] = i.ToString(); dt.Rows.Add(dr); } dg.DataSource = dt; dg.DataBind(); } can any one help me......
thank u
Here is what you can do. Before you bind your grid (on page load, or whenever) store you dataTable in viewstate.
//In page load ViewState["yourDataTable"] = dt; private void Addrow() { DataTable dt = (DataTable)ViewState["yourDataTable"]; int row = 0; while (row < dt.Rows.Count) { TextBox txt = (TextBox)this.GridView.Items[row].FindControl("txt"); dt.Rows[row]["txtValue"] = txt.Text; row += 1; } DataRow dr; dr = dt.NewRow(); dt.Rows.Add(dr); dg.DataSource = dt; dg.DataBind();
I didn't get any requirements for the signature
-
Here is what you can do. Before you bind your grid (on page load, or whenever) store you dataTable in viewstate.
//In page load ViewState["yourDataTable"] = dt; private void Addrow() { DataTable dt = (DataTable)ViewState["yourDataTable"]; int row = 0; while (row < dt.Rows.Count) { TextBox txt = (TextBox)this.GridView.Items[row].FindControl("txt"); dt.Rows[row]["txtValue"] = txt.Text; row += 1; } DataRow dr; dr = dt.NewRow(); dt.Rows.Add(dr); dg.DataSource = dt; dg.DataBind();
I didn't get any requirements for the signature
thnks.... my requirement is i need a grid with two rows and two cols with a textbox inside a gridcell.... i have a add button .... when an user clicks the add button...an extra row has to be generated...the values entered by the user in the textbox should be maintained i need the complete codings..can u plz send me that....
thank u