Rowupdating in gridview in asp net c example
Rowupdating in gridview in asp net c example - majestic dating erotic
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 the examples we've looked at so far, the Grid View's output is a tad drab and unattractive.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.I am using Template Field’s Item Template and Edit Item Template for providing read only and editing interface of the same column in the Grid View.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.To get the Primary Key reference we can use the Data Keys collection of the Grid View.
This collection only requires the row index no and it will give us the primary key.
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.
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.
In this article I will explain how to edit master-detail form using Grid View and Details View control in ASP.
Every one can use it to compare the new value with old ones.