This is a migrated thread and some comments may be shown as answers.

Saving multiple grids on one page

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Skaggs
Top achievements
Rank 2
Eric Skaggs asked on 04 Dec 2008, 07:17 PM
I have three grids on one page.  All three are in edit mode and only display one item.  There is only one "Save" button on the third grid at the bottom of the page in the CommandItemTemplate.  I would like to be able to edit all three of the grids, click the Save button in the third grid and have all the data in all of the grids saved.  I'm using the ItemCommand event on that third grid to enter a server-side function to perform the save.  However, I'm currently getting the error "Object reference not set to an instance of an object" when trying to reference another grid.  Is this possible and if so, can someone provide some guidance?

Thank you,

Eric Skaggs

1 Answer, 1 is accepted

Sort by
0
Eric Skaggs
Top achievements
Rank 2
answered on 05 Dec 2008, 10:05 PM
I think I've got it figured out.  When the page loads, three separate grids are displaying one item in edit mode (I've coded this as a requirement...you basically can't get to this page and have nothing in these three grids).  When you click the Save button on the third grid, you enter the ItemCommand event and run the following code:

GridEditFormItem item1grid1.Items[0].EditFormItem;  
GridEditFormItem item2grid2.Items[0].EditFormItem;  
GridEditFormItem item3grid3.Items[0].EditFormItem;  
 
TextBox txtbx1 = item1.FindControl("txtbx1") as TextBox;  
TextBox txtbx2 = item1.FindControl("txtbx2") as TextBox;  
TextBox txtbx3 = item1.FindControl("txtbx3") as TextBox;  
RadComboBox cbo1 = item1.FindControl("cbo1") as RadComboBox;  
RadComboBox cbo2 = item1.FindControl("cbo2") as RadComboBox; 

Obviously, I'm not doing anything with items 2 or 3 here.  The problem I had before was that I was referencing items 1, 2, and 3 as GridDataItems instead of GridEditFormItems.  Now that I've made that change, I'm referencing objects that DO exist on the page, which is always nice.  Now that I've got that working, I'll store the values in each of the controls in the grids and send those off to a stored procedure in the database to update all three grids at once!
Tags
Grid
Asked by
Eric Skaggs
Top achievements
Rank 2
Answers by
Eric Skaggs
Top achievements
Rank 2
Share this question
or