$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
ListView Sorting in ASP.NET
Home > How to > ListView Sorting

When using Kettic ListView UI control for ASP.NET AJAX project, sometimes you might want to apply a certain sorting to arrange your listview items in a way that is easier to locate and identify. Using Kettic ListView control, ASP.NET wed developers can achieve different types of item sorting with simple programming.
  • You can arrange listview items in ascending order;
  • You can arrange listview items in descending order;
  • You can sort items from a single field in a listview;
  • You can also sort items from a number of items at a time.
Apart from this guide for listview item sorting, we have also provided you with several other user manuals for listview. Please view the list below to see if it fulfills your requirements:
  • Read this guide to learn how to get started with ListView control
  • Read this guide to learn how to apply item grouping with ListView control
  • Read this guide to learn how to apply item filtering with ListView control
  • Read this guide to learn how to apply data binding with ListView control

How to Apply Sorting in ListView

After the introduction above, now you might already have a basic idea of the sorting capability for Kettic ListView control. In this section, we will show you how to apply item sorting in listview along with detailed aspx codes and Visual C# .NET demo codes.
Before we present the sample codes, it is necessary that we introduce you some basic properties to help you understand the sorting demo better.
  • SortOrder: This property is used to define the sorting order for your specified field / fields in listview. Now we provide Ascending order and Descending order for you to choose from.
  • AddSortExpression: This property is used to add your currently designed sorting expression to the collection of Sort Expression.
The following is simple demo, in which we set AllowMultiFieldSorting to true, and then apply ascending order for field 1, descending order for field2. You can make adjustment before copying to your ASP.NET evaluation project.
Aspx sample codes:
<kettic:PerListView ID="PerListView1" runat="server" ItemPlaceholderID="PlaceHolder1"
DataSourceID="SqlDataSource1" AllowMultiFieldSorting="true" >

</kettic:PerListView>
Visual C# .NET sample codes:
PerListViewSortExpression expression;
PerListView1.SortExpressions.Clear();
expression = new PerListViewSortExpression();
expression.FieldName = "field1";
expression.SortOrder = PerListViewSortOrder.Ascending;
PerListView1.SortExpressions.AddSortExpression(expression);

expression = new PerListViewSortExpression();
expression.FieldName = "field2";
expression.SortOrder = PerListViewSortOrder.Descending;
PerListView1.SortExpressions.AddSortExpression(expression);

Label1.Text = PerListView1.SortExpressions.GetSortString();
ASP.NET AJAX UI Controls