By Default, Grid View control displays Item Template which directly shows the Product Name and Unit Price columns but when user clicks Edit button Grid View automatically switches to Edit Item Template and display the control available inside Edit Item Template for user editing.
Now I will show you the C# code behind file of the above ASP.
Please keep in mind that there are many different ways to update the database using the Grid View control depending on the type of data you are updating and the functionality the user need and there are many solutions to achieve the same end result.
In the above tutorial I tried to give you one of the easiest solutions and I hope you can go explore Grid View control editing further after learning the basics from this tutorial.
The secret lies in the event handlers–in this case, the Row Updating event handler. Grid View Update Event Args object that is passed in. This page contains copyright material from //blog.and you have no rights to copy and paste the full text into your own blog even if you have written permission to the contrary.
Using the Row Updating handler, we can do whatever we want. 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 Find Contro By ID() method I demonstrated on Monday and updating the database using code. – For a while now I’m trying to figure out why my method, triggered by the Grid View.
I would need to set values passed to the Sql Data Source control on the update event, and as part of this I would need to reference the controls contained in the row being updated.
Visual Studio allows developers to quickly put together a Web Forms page simply using drag and drop options from the Visual Studio editor.
In this tutorial we are searching for our Text Box controls txt Product Name and txt Unit Price.
To get the Primary Key reference we can use the Data Keys collection of the Grid View.
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 Grid Views go.
One of the issues I’ve had is that the edit template doesn’t map to the view template very well. You see, the data that gets stored back to the database during the edit could go to two of four different tables.