473,378 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 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
May 30 '07 #1
3 26261
"Polaris" <et*******@hotmail.comwrote in message
news:u3**************@TK2MSFTNGP02.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 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

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

Polaris

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:OR**************@TK2MSFTNGP04.phx.gbl...
"Polaris" <et*******@hotmail.comwrote in message
news:u3**************@TK2MSFTNGP02.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 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

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

May 30 '07 #4

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

Similar topics

3
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...
6
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...
7
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...
5
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...
1
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...
3
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...
2
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...
5
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...
6
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.