How to add a row to datagrid at run time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

My datagrid reads and loades from a database 'select statement' fine. Then
after I have all rows on the screen, I want to be able to add a new row via a
button press. AFter that I would like to pupulate this new row with data
coming from the datbase again (via a dataset)
Does anyone know how to add a new row to a datagrid? I use the following
command:
short newIndex = (short) dataGrid1.Items.Count; //
dataGrid1.Items[newIndex].DataItem = new
System.Web.UI.WebControls.DataGridItem(1, 0, ListItemType.Item);

1 is the index of the new row(it should actually be the value of newIndex
but I=it gives me an out of range error!. The second paramter is the
datasetindex for data row# that comes from database, I don't know what to put
for this one.

Thanks a lot
 
Perhaps you can add the row to the dataset instead, rebind it to the grid,
set the edititemindex to the newly created row so a user can populate it,
then commit the changes to the database on the submit action. Something like
that.

--
Benjamin Strackany
http://www.developmentnow.com


Merdaad said:
Does anyone have an answer fot this?

Merdaad said:
Hi,

My datagrid reads and loades from a database 'select statement' fine. Then
after I have all rows on the screen, I want to be able to add a new row via a
button press. AFter that I would like to pupulate this new row with data
coming from the datbase again (via a dataset)
Does anyone know how to add a new row to a datagrid? I use the following
command:
short newIndex = (short) dataGrid1.Items.Count; //
dataGrid1.Items[newIndex].DataItem = new
System.Web.UI.WebControls.DataGridItem(1, 0, ListItemType.Item);

1 is the index of the new row(it should actually be the value of newIndex
but I=it gives me an out of range error!. The second paramter is the
datasetindex for data row# that comes from database, I don't know what to put
for this one.

Thanks a lot
 
Back
Top