GridView and Updating A Row Manually
A couple of days ago I mentioned a project that I’ve been working on that is a bit out of the ordinary as far as GridViews go. One of the issues I’ve had is that the edit template doesn’t map to the view template very well.
OK, it doesn’t map at all.
You see, the data that gets stored back to the database during the edit could go to two of four different tables. But the view is generated from a stored procedure that gathers the information from those tables and makes the result look like it came from one table.
So how do you have the GridView update the database under these conditions?
The secret lies in the event handlers–in this case, the RowUpdating event handler.
Using the RowUpdating handler, we can do whatever we want. The first line of code you need to make sure you include is
e.Cancel = true;
“e” represents the System.Web.UI.WebControls.GridViewUpdateEventArgs object that is passed in. What the line of code says is “cancel any other update processing that may have happened after this event gets called.”
From here on out, you’ll need to retrieve the values from your edit controls manually using the FindControByID() method I demonstrated on Monday and updating the database using code.
Other places talking about the GridView and Updating a Row
Programming Shorts : In GridView RowUpdating Event Handler, e … – I use custom data objects to populate data controls. Typically, I’ll create a factory object and factory method that returns a List collection of "ConcreteProducts". For example, RegistrationRuleFactory f = new …
sitecore with gridview – rowupdating event doesn’t fire – gridview to in web.config resolves this issue. your web.config would then look like : system.web.ui.webcontrols.repeater system.web.ui.webcontrols. …
in gridview rowupdating event handler, e.newvalues and e.oldvalues … – in the code behind, handle the gridview’s rowupdating event and access the form data as such: /// /// handle the row update event /// void rulesgridview_rowupdating(object sender, gridviewupdateeventargs e) …
DataBinding in ASP.NET 2.0 and the RowUpdating event – Dennis van … – For a while now I’m trying to figure out why my method, triggered by the GridView.RowUpdating event, doesn’t work as all samples say it should do. All samples of course assume you’re doing everything in your .aspx page, but I have to do …
GridView & RowUpdating — Or Dude, where are my new values? – Part of the consequence of that is that the GridView loses part of its functionality, like the RowUpdating event doesn’t provide OldValues and NewValues, instead they are blank. So here’s a scenario. You have a list, like the following …
Simple Insert, Select, Edit, Update and Delete in Asp.Net GridView … – The above block of codes in RowUpdating event, finds the control in the GridView, takes those values in pass it to the CustomersCls class Update method. The first parameter GridView1.DataKeys[e.RowIndex].Values[0]. …
Related Post
One Pingback/Trackback
- 04 November 2009 at 8:11am
- Dew Drop – November 4, 2009 | Alvin Ashcraft's Morning Dew
[...] GridView and Updating a Row Manually (Dave M. Bush) ...



Pingback: Dew Drop – November 4, 2009 | Alvin Ashcraft's Morning Dew