How to add a row to datagrid at run time

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
 
B

Ben Strackany

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top