This CSASPNETGrid View project describes how to populate ASP.NET Grid View control and how to implement Insert, Edit, Update, Delete, Paging and Sorting functions in ASP. We have received many posts in forums about this popular web control, so this sample provides a complete sample for showing how to implement these basic functions of this control.

gridview rowupdating code-10

This sample contains a Sql Server database file, if you do not install Sql Server, The Data In page can also works fine.

More information about Sql Server 2008 R2 Express and download links can be found here: Please follow these demonstration steps below. Expand the CSASPNETGrid View web application and press Ctrl + F5 to show the Data From

Step 2: We will see a Gird View control on the page, you can add, edit, delete the columns of the Grid View control, the data is come from App_Data/Grid file, and the Grid View's status is stored in View State for persisting data across postbacks.

Step 3: The Grid View the page size is 15, you need insert 16 Persons in this Grid View to see the next page. NET Empty Web Application" in Visual Studio 2010 or Visual Web Developer 2010. The project includes two web form pages for demonstrating two ways to bind data source with the Grid View, name them as "Data From Data Base.aspx", "Data In Memory.aspx". Before we start to write code, we need install Sql Server 2008 R2 Express and create a database file as the data source of Grid View control.

Please click the title of the Grid View to sort the result by Person ID, Last Name or First Name properties. Add an folder "App_Data" and create a Sql Server Database,"Grid View.mdf".

Step 4: Please press Ctrl+F5 to show Data In page, the test steps just like Data From Data Add "Person" table with three fields "Person ID","First Name","Last Name", Person ID is the primary key of the table, and you can insert some default values in Person table. Drag and drop a Grid View control, two Link Button controls, two Text Box controls and a Panel control into Data From Data page.

The Grid View is used to display, edit and delete the data of database file, the Text Box and Link Button are used to insert new items to the data table.

In the first step, check your controls and rename them and set some basic properties of the Grid View, such as Grid View's templates and events. Copy the Page_Load and Bind Grid View methods of the sample and paste them to your Data From Data cs file, and navigator to the Property panel and switch to Event.

Double click on the following event and generate the Event Handlers, after that, fill the generated methods with the sample code. Double click on the Click event of Link Button control to generate the event handler and fill the generated methods with the sample, these two button are used to add new items to the database file and cancel the insert operate. The Data In page is pretty much the same with Data From Data page, this web page get data from memory, instead of database file.