ListView control has built in capability to sort data.  Please refer to Tip#5 to get started with Databinding of list view control. Once that is done, we can move on to sorting the ListView data with the following steps.

1. Add a button control inside of LayoutTemplate of ListView.

2. Set its CommandName property to  ’Sort’.

3. Set its CommandArgument property to the table column name on which the sorting has to be done. In this case it is set to CategoryName as shown in the picture below.


4. Now press CTRL +F5 to run the page.

5. Click on SortByName button to sort Data by CategoryName. Clicking on the button continuously will alternately sort data in ascending and descending fashion. The final data will be sorted as shown in the picture below:


That was simple, wasn’t it?

Reshmi Mangalore

SDET, Web Development Tools