Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is ADD function in a DataGrid possible?

Status
Not open for further replies.

DLLHell

Programmer
May 9, 2003
69
US
The Data Grid provides Edit/Update/Cancel & Delete buttons (I've yet to get these working). Is it possible to use a DataGrid to Add records, or am I going to have to create a custom Add button that creates a separate Web page to facilitate the Add of new records into a dataset?

Thanks.
 
Awesome handle man (DLLHell...ah, the memories of vb6.0 coding...)

Anyway, first to answer your edit/update/cancel question:

By deafult, each of the buttons (edit/update/cancel) is linked to an event of the datagrid which happen to be (surprise surprise) EditCommand, UpdateCommand, CancelCommand. So if you're having problems getting them to work correctly, check to make sure you're using the right events in the code behind.

Now to the second part, adding an item...

option1:
above/below your datagrid, have a button that says add, and some textboxes or whatever to specify the values. When the user clicks add, the record gets saved to the database, you get your dataset over again, and bind it to the datagrid. This will then include the new item.

I think thats the best way IMHO, mainly because the user can be sure that each item they add is actually saved to the db. You could try and do something where the items just get added to the data grid, and then the users have to hit a button to update any new items, but that gets messy:
- what if they close their browser? new items are gone
- what if they forget they have to update?
- etc.

hth

D'Arcy
 
Thanks, JFrost. I was thinking about the 2nd option (add & then effect an update) but your idea about the Add button & textboxes in one row is very good. I think I have room for it on the webpage.

Hopefully in .Net I won't be in DLL Hell anymore & can change my handle someday!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top