473,769 Members | 3,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add a row into GridView?

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 programmaticall y 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
May 30 '07 #1
3 26285
"Polaris" <et*******@hotm ail.comwrote in message
news:u3******** ******@TK2MSFTN GP02.phx.gbl...
I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the
GridView to display data. I need to programmaticall y 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

May 30 '07 #2
Thanks, but I would not come to this group had I fund it in google.

Polaris

"Mark Rae" <ma**@markNOSPA Mrae.netwrote in message
news:OR******** ******@TK2MSFTN GP04.phx.gbl...
"Polaris" <et*******@hotm ail.comwrote in message
news:u3******** ******@TK2MSFTN GP02.phx.gbl...
>I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the
GridView to display data. I need to programmaticall y 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

May 30 '07 #3
On 30 May, 20:00, "Polaris" <etpola...@hotm ail.comwrote:
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 programmaticall y 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

May 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5677
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the GridView to allow entry of quantity and Y/N switch for
6
3041
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
7
14819
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
5
4838
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
1
5216
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView is not displayed. I set the datasource and then bind the GridView. I've tried disabling the...
3
4605
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a datasource to this GridView in runtime. But I cannot
2
13200
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
5
3007
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the page is posting back when the DDL is selected / chaged, but the event is never being called. Any...
6
5756
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the OnSelectedIndexChanged event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndexChanged event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the...
3
5244
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.