Hello,
I am coding i .net using c# as codebehind. I have a datagrid that I want to add one or more new rows to, and the new rows should be added at the bottom of the grid. The datagrid is not bound to any database.
The datagrid is named DataGrid1. Is there any way of just adding a new row to this datagrid whitout clearing all information that is stored in the datagrid from before?
I`m doing something like this now:
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("Text", typeof(string)));
dt.Columns.Add(new DataColumn("LineID", typeof(Int32)));
dt.Columns.Add(new DataColumn("repeats", typeof(string)));
foreach (DataGridItem dataGridItem in Datagrid1.Items)
{
repeats = ((TextBox)dataGridItem.FindControl("repeats")).Text;
if (repeats != "")
{
for (int i = 0; i < Convert.ToInt32(repeats); i++)
{
dr = dt.NewRow();//Adds a new row and adds text and id to this row
dr["LineID"] = lineId;
dr["Text"] = textline;
dt.Rows.Add(dr);
}
}
}
Datagrid1.DataSource = dt;
Datagrid1.DataBind();
Here I am searching for a value in the grid, if I find that value a new row should be added. But this removes all rows in the datagrid except the only one that is added here.
Is there any easy way of just adding a row to a datagrid that already is printed? There is no database connection involved, the information is not supposed to be stored.
Anybody knows how to do this?
Loading
halvornPosted Aug 16, 2006, 4:52 AM
The datagrid contains data, each time the datagrid is loaded it fetches information from some html-page. Then the user should add some values to the grid(Not storing anything in database at this point is important)
I`m not sure how to add new rows to the datatable and bind along with existing info. Anybody knows how to do this? What I do in this code is that I make a new datatabe and bind it to the grid, but this removes all previous information...
Thanks for any help :)
SreekarPosted Aug 16, 2006, 2:44 AM