That’s why I have placed different templates like Item Template (for normal view) and Edit Item Template (for edit view).to modify update behavior before it happens, to provide additional handling when an update will occur, to retain a reference to an updated row, to cancel the current update and schedule it for a batch process to be processed later, and so on. To do that, instead of creating four Stored Procedures to perform these tasks I will create a single Stored Procedure to satisfy my requirements and I will access it in code behind depending on the action performed by the end user on a button click.I have written this article specially focusing on newcomers and anyone new wants to insert, update and delete records in a Grid View using a Single Stored Procedure, so let us start with a basic introduction.' Assumes that connection is a valid Sql Connection object. Dim cust Adapter As Sql Data Adapter = New Sql Data Adapter( _ "SELECT Customer ID, Company Name FROM Customers", connection) ' Add handlers. Row Updating, New Sql Row Updating Event Handler( _ Address Of On Row Updating) Add Handler cust Adapter. Row Updating, _ New Sql Row Updating Event Handler(Address Of On Row Updating) Remove Handler cust Adapter. Row Updated, New Sql Row Updated Event Handler( Address Of On Row Updated) ' Set Data Adapter command properties, fill Data Set, and modify Data Set. Update(cust DS, "Customers") ' Remove handlers. Row Updated, _ New Sql Row Updated Event Handler(Address Of On Row Updated) Private Shared Sub On Row Updating(sender As Object, _ args As Sql Row Updating Event Args) If args.
This example shows how to edit and update records in a Grid View in ASP. This example is helpful in situations where an administrator needs to edit several records from the database.Now after clicking on the "Save" button, the hidden field value takes the value "Insert" and es it to the Stored Procedure as the action and because of this the Stored Procedure will execute a particular type of block.Now at page load I have called the method, so after that the grid will fill as in: Now click on the Edit button that calls the edit method as shown in the following grid: If you click on the "Cancel" button then the editcancel method will be called and edit mode will be cancelled.You can hide a Command Field or Button Field based on the position (index) in the Grid View.Generally Grid View is used to show data in tabular format. I have taken an example of a simple database table of having User Name, Password, Super Password, User Type, Admin Desc and Active fields.For demonstration I have created a database (named Database.mdf) in which we have a table named tbl_Employee.