|
Page 3 of 3
.
.
.
To test the page
1. Switch to Open the Default.aspx page, and then press CTRL+F5 to run the page.
2. The GridView control is displayed with StudentId, StudentName, StudentAge, and CourseId columns. Click a column heading to sort by the contents of that column.
Editing the GridView control data
The GridView control already contains all the functions necessary for editing data, since the control is abstract and generic. In fact this is the greatest strength of the GridView control over the DataGrid control.
The GridView control uses the assigned data source to edit the data records and the developer will have to add an additional query to the SqlDataSource control for updation of data. The code would be something like the one illustrated below.
updateCommand="UPDATE StudentMaster SET StudentName=@StudentName, StudentAge=@StudentAge WHERE(StudentMaster.StudentID=@StudentId)"
When the AutoGenerateEditButton property is set to true, the GridView displays an additional column. When update is clicked the GridView searches for an appropriate command object on the underlying data source. It fires the rowUpdating event and checks the CanUpdate property of the data source.
Deleting Displayed Records
Deleting records is similar to updating and Editing. The GridView rides on the data source’s ability to perform data operations. The record deletion is enabled by specifying the AutoGenerateDeleteButton to True. The GridView then renders a column of Delete buttons for each row on the GridView. The data source method is passed as a dictionary key filed name/value pair to uniquely identify the row to delete. However, the GridView does not provide any feedback on the operation.
Inserting Records
GridView does not support inserting data against a data source object.
Using Templates
Individual templates can be defined for each field.

Assigining data binding to a control within a template is easy. Besides individually created fields, the GridView control offers two integrated Templates, PageTemplate and NullTemplate. The latter is useful when an assigned data source returns an empty list of data records. A message can be flashed to the user if an empty record set is returned.

The GridView indeed comes with a lot of goodies. Developers are freed from the large volume of code that had to be written. Though the look and feel of the GridView is similar to the DataGrid, it is really very different.
In the next section we shall examine the DetailsView which is a complementary to the GridView in several ways.

Trackback(0)

|