Gridview rowupdating event code

Rated 4.11/5 based on 964 customer reviews

Last line of the following code is calling a local method for updating the database and passing all the parameters to this method.

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.

Summary : Usually developers do not use an editable Grid View for many reasons. First fill then create a bool function and go to assemble row editing & updating event.

Developers prefer manual coding but an editable Grid View is a good way to update a database. Step 1Put a Grid View in your aspx page then write code for the page load to fill the Grid View.

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.

gridview rowupdating event code-63

gridview rowupdating event code-56

gridview rowupdating event code-84

I am sharing this because I see a lot of questions on the forums on how to get the value from the Grid View object, and I know how.

Now I will show you the C# code behind file of the above ASP.

NET page that will handle different Grid View events to provide complete editing functionality.

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.

Leave a Reply