Freigeben über


Tip #7 Did you know… How to Sort data using a ListView control?

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.

Sorting

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:

SortedByCategoryName

That was simple, wasn’t it?

Reshmi Mangalore

SDET, Web Development Tools

Comments

  • Anonymous
    September 01, 2008
    PingBack from http://hoursfunnywallpaper.cn/?p=4076

  • Anonymous
    September 02, 2008
    My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. Sara Ford's Tip of the Day #303 covers the QuickWatch window . Carlos Quintero posted The diagram of the convoluted build configuration

  • Anonymous
    September 15, 2008
    The comment has been removed

  • Anonymous
    September 15, 2008
    The comment has been removed

  • Anonymous
    June 16, 2009
    原文地址:HowtoSortdatausingaListViewcontrolListView内置数据排序的功能,有关listView绑定数据的功能参见:webdeveloper...