Bidirectional Sorting on Any Column in DataGrid
page 5 of 7
by Pani Baruri & Abhijit Mandrekar
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 25240/ 47

Part 2: Using Attributes Proporty and Data View

The part 1 example has slight limitation on the programmer side who wants to use the code above as is. The limitation is he/she has to remember to set the sortexpression property of column in datagrid as database field name followed by sort direction at design time e.g. lastname ASC.

 

The following example illustrates the use of adding sortexpression and sortdirection dynamic attributes to datagrid, maintain their state through view state and sort data in datagrid using dataview. The sortexpression property of datagrid set in this example is to generate sortcommand event only. The sortexpression attribute of datagrid stores last column name used for sorting and sortdirection attribute stores last direction used for sorting.

 

Design Time:

 

  1. Drag and drop a DatGrid on the form.
  2. Set AllowSorting property of the grid to True.
  3. Set AutogenerateColumns property of the grid to False.
  4. Add bound columns to datagrid and set their properties as follows. The sortexpression property refers to the name of column in database table.

 

Note: Employees table from Northwind database is being used to illustrate the purpose.

 

DataTextField

Header Text

Sort Expression

EmployeeID

Employee ID

EmployeeID

LastName

Last Name

LastName

FirstName

First Name

FirstName

Title

Title

Title

City

City

City

Country

Country

Country

 

 


View Entire Article

User Comments

Title: Bidirectional Sorting on Any Column in DataGrid   
Name: brian
Date: 2007-08-08 10:39:14 PM
Comment:
thanks a lot.It really very helpful
thumb up

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-19 10:06:29 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search