Complex Data Binding with the Accordion Control
page 5 of 6
by Brian Mains
Average Rating: 
Views (Total / Last 10 Days): 40695/ 74

Grid Editing

The gridview fires the RowEditing event whenever the mode changes from read-only to displaying an edit interface. To invoke editing, click a button with the CommandName set to Edit. The grid needs three things: the AutoGenerateEditButton property needs set to true, the RowEditing event needs an event handler attached to it, and the grid needs rebound with the EditIndex property set to the current row (before the data bind). Take a look at the approach below. This event is wired up to each grid in the accordion.

Listing 12

protected void gvwOrders_RowEditing(object sender, GridViewEditEventArgs e)
  GridView grid = (GridView)sender;
  grid.EditIndex = e.NewEditIndex;
  HiddenField customerKeyField = (HiddenField)grid.FindControl("hdnCustomerKey");
  this.BindGrid(grid, new Guid(customerKeyField.Value));

Notice that the method pulls the key from the hidden field setup in the accordion template, and uses the same BindGrid method to repopulate the grid.

Update works in a similar manner; any updates need to be performed manually, as shown below.

Listing 13

protected void gvwOrders_RowUpdating(object sender, GridViewUpdateEventArgs e)
  GridView grid = (GridView)sender;
  GridViewRow row = grid.Rows[e.RowIndex];
  string totalAmount = ((ITextControl)row.Cells[1].Controls[0]).Text;
  string referenceNumber = ((ITextControl)row.Cells[2].Controls[0]).Text;
  string createdDate = ((ITextControl)row.Cells[3].Controls[0]).Text;
  //Update the record

Each field to update is extracted by retrieving the value from the textboxes that hold the value. I did not show it above, but the values pulled back from the textboxes are passed to the customer record for the selected customer. This record is then submitted to the database.

View Entire Article

User Comments

Title: Need Code   
Name: Dorababu
Date: 2011-11-20 12:55:11 PM
Hi i am unable to view the article can any one post me the code used in this please
Title: I don't have any   
Name: Seyed
Date: 2009-12-08 7:45:02 PM
Big time saver. Thanks for this great posting
Title: Thanks   
Name: Lee
Date: 2009-11-23 7:59:39 AM
It is a great article. will be helpful if u can provide me the all related code + screenshots
Title: Good Article......   
Name: WebEye
Date: 2008-08-30 5:51:42 AM
Very good me a lot.
You can find very much same article here...

And running example of this article here...
Title: Nice Article   
Name: Imran Ahmad Mughal
Date: 2008-07-08 1:09:50 AM
It's really a nice article. Can you please provide me the sample project in which you have implemented this?

Title: Thanks   
Name: Subalakshmi
Date: 2008-07-03 6:39:09 AM
A very Good article,to implement in my website.
Title: Thanks   
Name: Prashanth
Date: 2008-07-03 5:16:01 AM
Great article, one small suggestion, if you have a sample application to download and some screen shots of the page it would be very helpful.
Title: Thank You :)   
Name: Qureshi
Date: 2008-07-01 9:20:20 AM

i realy want to say thanks

bcoz i really want a article on this

thaks a tan

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-14 3:01:11 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search