Database
SQL ServerUsing ASP.NET 3.5's ListView and DataPager Controls: Sorting Data with the ListView Control
When binding data to a GridView using a data source control, enabling sorting is as simple as ticking the "Enable Sorting" checkbox in the GridView's Smart Tag. Enabling sorting turns each GridView column's header into a LinkButton that, when clicked, causes a postback and re-binds the data to the GridView, sorting it by the clicked column.
Likewise, enabling sorting in the ListView is a fairly simple and straightforward process and can be accomplished without writing a line of code.
The main challenge with enabling sorting in the ListView control is that there are no pre-defined columns, like with the GridView. Therefore, we are on
the hook for defining and implementing the sorting interface. But once this is setup, the ListView can internally handle the sorting logic without the
need for us to write any additional code. Of course, in more advanced scenarios we may need to manually sort the data or programmatically specify the
sort expression used to internally sort the data. Prior to sorting, the ListView raises its Sorting event handler, which is an ideal place
to add any additional sort-related logic. Moreover, the ListView control's sorting logic can be programmatically invoked via its Sort method.
In this article we will look at how to enabling sorting in the ListView control. We will look at using the ListView's simple, baked in sorting functionality.
Following that, we will see how to programmatically invoke this sorting logic via the Sort method as well as more advanced scenarios. Read
on to learn more!
Read More >
Sponsored Links
Subscribe via RSS
SQL Server
- Naming Database Objects: Part II
- Trace Messages Part V: Trace Cleanup
- Naming Database Objects: Part I
- Multiple-Child Aggregation
- Creating SQL Tables for an Integrating Application Using Dexterity
- SQL Server 2005 Beta 2 Transact-SQL Enhancements
- .NET Rocks! - Brian Larson on SQL Server Reporting Services
- Computing the Trimmed Mean in SQL
- SQL Server 2000 Gains on Oracle
- Separator First Formatting (SFF)
