Gridview rowupdating code in asp net
Gridview rowupdating code in asp net - amber marshall dating graham
In this article, we will explore how to add, update, delete and select a record from sql server database using gridview control in a simple way.I’m using visual studio 2008 and sql server 2008 for this sample.
Actually gridview control is built with lot of features and this control is commonly used for all applications.And here I’m explaining some basic functions of this gridview control such as insert edit and delete a record.First, we need to prepare the database table and stored procedure for gridview operations such as insert, update & delete a records, here I’m using sql server 2008 for all database activities, for this sample I have created the customer table and stored procedure for all mentioned gridview operations.Create the customer table in your own test database using below table script and insert some records initially to load gridview with data.Once you execute the above table and insert scripts, you will get the below records in the table initially to load data into gridview control.Execute the below SP_Customer stored procedure in sql server database which is used to handle insert, update, select and delete a record into customer table.
Here we are not deleting a record permanently but using active flag column, make it inactive the record while doing the delete operation then make it active and get it whenever you want.This is the easy way to handle all the gridview operations in data base side instead of using sql query from front end side.Also here we used @@ERROR for error handling in the stored procedure and returns the number to front end and confirm that the performed action is successful or not.Now we have prepared the all database related activities for this and moving to front end side to setup aspx page and codebehind file to handle gridview operations, so first create the web application and add Gridview page as shown below.Now we have created the application and open the web.config file to add connection string as shown below.Connection string must be based on your database details. Drag the gridview control from tool box and placed into the page and make it Autogeneratecolumns as false, so manually we will create the gridview columns to display.