Gridview rowupdating code in asp net
In data driven web sites, users are normally allowed to view data and administrators are allowed to add, edit or delete data.
In this tutorial I will show you how you can create an editable Grid View control for administrators to modify database records directly into the Grid View control.
In this tutorial we are searching for our Text Box controls txt Product Name and txt Unit Price.
In the Page_Load event, you simply load your data from the database and bind it with the Grid View control as shown below: For brevity I am not storing connection string in the web.config and also not using any Data Access Component.
Next event is the Grid View Row Editing event to give ASP. You need to set the Edit Index property of the Grid View with the New Edit Index property of the Grid View Edit Event Args class.
If user clicks the Cancel button while Grid View is in editing mode, you need to Cancel the Editing process and also need to reset the Edit Index property to -1 in the Row Canceling Edit event of the Grid View control as shown below: The last step is to handle the Row Updating event to actually update the back end database.
To do this we first need to obtain the reference of the current row by using its index no as shown in the first line below.
Search for gridview rowupdating code in asp net:
In the above code, I set two properties Show Edit Button and Show Cancel Button of Command Field.