alt
Advertisement
Sponsored links
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow ASP.NET 2.0 arrow ASP.NET 2.0 : Adding Sorting and Paging in GridView
Site Search


ASP.NET 2.0 : Adding Sorting and Paging in GridView
Article Index
ASP.NET 2.0 : Adding Sorting and Paging in GridView
Page 2
Page 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)
Comments (2)add comment

WhoCares said:

  More interesting would be custom paging with custom sorting. Your sample is trivial.
March 21, 2007

yogarajan said:

  Hi all,
I need to display two sets of records.
The second one should come under the first set of records and also second one uses the first one's unique id.
for example,
First table values
id Show/hide button checkbox category
1 car (parent)
Maruthi (child)
BMW(child)
HeroHonda(child)
Yamaha(child)

2 bike

3 fruits
Apple
Orange
Mango
.
.
.
(etc)


1. if i click show button that time only child grid is show . button caption change to 'hide'
2. if i click hide button that time only child grid is hide. button caption change to 'show'

2. if i select parent checkbox (ie. checked)(ex. parent -> car ) that corresponding child grid (ex. child -> Maruthi, BMW, HeroHonda, Yamaha) also select(ie. checkbox checked)
-----------
So, How to Do it?.
August 30, 2007

Write comment

busy

 
< Prev   Next >
Exforsys Offers
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape