Dave's Notebook

GridView and Updating A Row Manually

G07L0095 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 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. … 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 … 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]. …