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 >