PC Review


Reply
Thread Tools Rate Thread

How to add a row into GridView?

 
 
Polaris
Guest
Posts: n/a
 
      30th May 2007
Hi Experts:



I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the
GridView to display data. I need to programmatically add rows into the
GridView. So far could not find a way to do it. I appreciate it if any one
can show a piece of code doing that.



Thanks in advance!



Polaris


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      30th May 2007
"Polaris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the
> GridView to display data. I need to programmatically add rows into the
> GridView. So far could not find a way to do it. I appreciate it if any one
> can show a piece of code doing that.


Google is your friend:
http://www.google.co.uk/search?sourc...ew%3e+add+rows


--
http://www.markrae.net

 
Reply With Quote
 
Polaris
Guest
Posts: n/a
 
      30th May 2007
Thanks, but I would not come to this group had I fund it in google.

Polaris

"Mark Rae" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Polaris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the
>> GridView to display data. I need to programmatically add rows into the
>> GridView. So far could not find a way to do it. I appreciate it if any
>> one can show a piece of code doing that.

>
> Google is your friend:
> http://www.google.co.uk/search?sourc...ew%3e+add+rows
>
>
> --
> http://www.markrae.net



 
Reply With Quote
 
Phil H
Guest
Posts: n/a
 
      30th May 2007
On 30 May, 20:00, "Polaris" <etpola...@hotmail.com> wrote:
> Hi Experts:
>
> I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the
> GridView to display data. I need to programmatically add rows into the
> GridView. So far could not find a way to do it. I appreciate it if any one
> can show a piece of code doing that.
>
> Thanks in advance!
>
> Polaris


Hi Polaris

Gridview does not have direct support for inserting records. It can
only display the rows for data that already exists with a built-in
means of editing and updating.

It is possible to write code that will insert a blank record (with
default column values in cases where nulls are not allowed) into the
underlying data table, reload the grid with the databind method, then
put the grid into edit mode with the editindex property set to the
index of the new record. This is messy and complicated because your
code would have to calculate the index value of the new record, which
is not simple if the grid is paged. This may be why insert is not
supported with GridView.

It's much easier to use FormView for this purpose which only displayes
one record at a time. FormView has an insert mode and makes it much
simpler.

Hence to achieve what you require (i.e. to add a means of inserting a
new record in addition to displaying a list in a GridView control) you
need both types of control in your application to handle the data. Add
a button somewhere on the web form to signal that the user wishes to
add a new record, then code the event handler to switch to displaying
the FormView control (in insert mode) instead of the GridView. When
the user clicks the button on the FormView to save the new record, use
the ItemInserted event handler to switch back to displaying GridView
(re-executing Databind if necessary).

HTH

P Hall

 
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
GridView's selection isn't causing other GridView's to load data asexpected Rasika WIJAYARATNE Microsoft ASP .NET 0 14th Dec 2007 12:25 AM
Creating custom gridview (inheriting from gridview class) =?Utf-8?B?V2ViTWF0cml4?= Microsoft ASP .NET 1 22nd Oct 2006 12:56 AM
Deleting row from GridView causes ArgumentOutOfRangeException during System.Web.UI.WebControls.GridView.set_SelectedIndex(Int32 value) loga123 Microsoft ASP .NET 2 28th Jun 2006 09:32 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= Microsoft ASP .NET 1 9th May 2006 07:48 PM
Gridview with combobox whose data is dependent on field in gridview wallermj@hotmail.com Microsoft ASP .NET 3 21st Nov 2005 05:34 PM


Features
 

Advertising
 

Newsgroups
 


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