473,396 Members | 1,789 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,396 software developers and data experts.

gridview add / insert button


I know native gridview does not support this and/insert of new rows..
what's killing me is I use to have this code that worked around this
but somehow I lost it. I recall suffering through it.

Would anybody have a sample of this in vb.net?

A simple gridview with line edit option an add button outside the
grid. When the add is selected a blank row with textboxes and dropdowns
at the top of grid allows for insert of a new row into the grid.

I have some notes, but can't seem to piece it together ...

Some clues from my notes:

Button puts gridview in edit mode.

GridViewRow newRow = GridView1.CreateRow(0, 0, 1, 2);
DataBind();

or

ds.Tables[ "Products" ].Rows.InsertAt( BlankRow, 0 );
and bind

to insert the blankrow at the top of the grid.

Kicking myself for having lost the code.

Thanks for any help, code or information!

Jan 26 '07 #1
3 3914
something like this

Protected Sub AddButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddButton.Click

' A code to insert a new row to the database
...........................

' then...
DataGrid1.CurrentPageIndex = 0
DataGrid1.EditItemIndex = 0

' Load all rows again
LoadGridViewAgain()

End Sub
On Jan 26, 4:41 am, "jobs" <j...@webdos.comwrote:
I know native gridview does not support this and/insert of new rows..
what's killing me is I use to have this code that worked around this
but somehow I lost it. I recall suffering through it.

Would anybody have a sample of this in vb.net?

A simple gridview with line edit option an add button outside the
grid. When the add is selected a blank row with textboxes and dropdowns
at the top of grid allows for insert of a new row into the grid.

I have some notes, but can't seem to piece it together ...

Some clues from my notes:

Button puts gridview in edit mode.

GridViewRow newRow = GridView1.CreateRow(0, 0, 1, 2);
DataBind();

or

ds.Tables[ "Products" ].Rows.InsertAt( BlankRow, 0 );
and bind

to insert the blankrow at the top of the grid.

Kicking myself for having lost the code.

Thanks for any help, code or information!
Jan 26 '07 #2
DataGrid1.CurrentPageIndex = 0
DataGrid1.EditItemIndex = 0
IMHO, it should have been DataGrid1.EditItemIndex = -1
:)
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
Jan 26 '07 #3
I'm working with Gridview under asp.net 2.0.

actually -1 t takes me out of edit mode.

= 0 causes me to go to edit mode on the top row.

I guess my question is, how can I add a blank row to the top of
gridview, not actually insert it into the data that that the grid is
bound to. this way in edit mode when I hit update, it will try to
insert whatever was keyed in. I use to have code to do this.

Jan 26 '07 #4

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

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
0
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a...
13
by: AG | last post by:
I have a gridview that I bind to a List(of Type) at runtime. Not using a datasource control. The gridview has a template column with an imagebutton whose commandname is set to 'Delete'. The...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
3
by: Polaris | last post by:
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...
0
by: Eraser | last post by:
Hi to all .NET guru guys... I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
2
by: shapper | last post by:
Hello, I am working with a ListView but I suppose that with a GridView might be the same. Instead of having an Insert Button on each GridView row I would like to have only one Insert button,...
2
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. ...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.