VB.Net GridView Sorting in ASP.Net

The ASP.Net GridView control property AllowSorting enables you to render the control with Sorting feature that can be handled at server side using VB.Net code logic easily. You can set the SortExpression property of BoundField or TemplateField of GridView control by specifying the name of the Data Column on which you want to map the Sorting function.

Sorting Event Used

1. OnSorting

The OnSorting event can be attached to the GridView control using VB.Net that enables you to apply the dynamic code to bind the data items in the specified sort order to the ASP.Net GridView control.

 

GridView Sorting Properties Used

1. AllowSorting (GridView)

2. SortExpression (BoundField or TemplateField)

 

The AllowSorting property accepts a boolean value as true/false that enables or disables the auto sorting feature of gridview control. The SortExpression property of BoundField or TemplateField accepts the value as name of the data field that you can pass to the sorting function that performs the sorting action based on that SortExpression.

 

Try the sample below to understand the functionality of VB.Net Sorting code applied to the ASP.Net GridView control:

 

ProductIDProduct NameUnits In StockPrice Per Unit
1Chai3918.0000
2Chang1719.0000
3Aniseed Syrup1310.0000
4Chef Anton's Cajun Seasoning5322.0000
5Chef Anton's Gumbo Mix021.3500
6Grandma's Boysenberry Spread12025.0000
7Uncle Bob's Organic Dried Pears1530.0000
8Northwoods Cranberry Sauce640.0000
9Mishi Kobe Niku2997.0000
10Ikura3131.0000
  • HIRE EzineASP.Net Developers