PC Review


Reply
Thread Tools Rate Thread

How to add a row to datagrid at run time

 
 
=?Utf-8?B?TWVyZGFhZA==?=
Guest
Posts: n/a
 
      15th Aug 2005
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWVyZGFhZA==?=
Guest
Posts: n/a
 
      17th Aug 2005
Does anyone have an answer fot this?

"Merdaad" wrote:

> 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

 
Reply With Quote
 
Ben Strackany
Guest
Posts: n/a
 
      18th Aug 2005
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" <(E-Mail Removed)> wrote in message
news:AF65C31B-9056-4CEE-B1CE-(E-Mail Removed)...
> Does anyone have an answer fot this?
>
> "Merdaad" wrote:
>
> > 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom collection was binded at design time, but does not populates datagrid at run time... SammyBar Microsoft Dot NET Framework Forms 2 21st Sep 2005 08:29 PM
Custom collection was binded at design time, but does not populates datagrid at run time... SammyBar Microsoft Dot NET 2 21st Sep 2005 08:29 PM
Design Time vs Run Time DataGrid =?Utf-8?B?cmtibmFpcg==?= Microsoft ASP .NET 1 1st Feb 2005 08:11 PM
Re: MS Access Date/Time, remove Time part from DataGrid ? Microsoft ADO .NET 2 15th Jul 2003 07:23 PM
RE: MS Access Date/Time, remove Time part from DataGrid ? Brett Keown [MSFT] Microsoft ADO .NET 0 15th Jul 2003 07:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 AM.