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

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


Other Related Items:

Floating Leaf and Debris Pond Net - 7 ft. x 10 ft.Floating Leaf and Debris Pond Net - 7 ft. x 10 ft.Protect your fish from predators and keep the autumn leaves out with Supreme Floating Pond Netting. Tough, durable netting floats on surface for easy set up and removal.
Building Secure Microsoft ASP.NET Applications (Pro-Developer)Building Secure Microsoft ASP.NET Applications (Pro-Developer)This guide presents a practical, scenario-driven approach to designing and building security-enhanced ASP.NET applications for Microsoft® Windows® 2000 and version 1.1 of the Microsoft .NET Framework.
Beginner's ASP.NET in VB.NET 2003 on DVDBeginner's ASP.NET in VB.NET 2003 on DVDASP.NET (VB.NET) 2003 represents an important technology for building enterprise level web applications. Learn the basics of ASP.NET development as yo... Read More >

Related Post

One Response to “GridView and Updating A Row Manually”

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor