Reputation: 427
I want to add a row to UnBounded DataGridView in Asp.net. I can create rows like this in Winform but don't know how to add row in ASPX as it don't have GridView.Rows.Add() method.
This is my code
Datatable declare at page load event.
dt.Columns.Add("Account_Code", Type.GetType("System.String"));
dt.Columns.Add("Account_Name", Type.GetType("System.String"));
dt.Rows.Add();
int rowCount=dt.Rows.Count-1;
dt.Rows[rowCount]["Account_Code"] = txtAccountCode.Text;
dt.Rows[rowCount]["Account_Name"] = txtAccountName.Text;
gvVoucherDetail.DataSource = dt;
gvVoucherDetail.DataBind();
When I see the datatable in the debuging mode it shows me row added to DataTable. But not sure why it is not showing in the web page. Any idea?
Upvotes: 0
Views: 1974
Reputation: 11
you will need to save the datatable in a session variable to maintain the state during postbacks. Here's a link tha I used to get it to work.
http://www.tek-tips.com/viewthread.cfm?qid=1282063
Upvotes: 1
Reputation: 37543
Because when you bind it, it clears all existing rows and injects its new rows. If you want the manually added rows to appear after a DataBind call, you have to add them either after the RowDataBound events have completed or during that process.
Upvotes: 0