I’m studying for a M$ certificate. I use the ‘self-paced’ Training Kit (book). I bumped into something which confuses me a bit. After finding some code samples online doing the same, I decided to ask the community.
This is the text:
The DetailsView control does not directly support sorting, whereas the GridView control
does. However, you can use the DataSource control, as discussed in Lesson 1, to manage data
sorting.
And here is a snip from the sample code in the book:
<asp:DetailsView runat="server" Width="300px"
ID="DetailsView1"
AllowPaging="True"
AutoGenerateRows="False"
DataKeyNames="ProductID"
DataSourceID="SqlDataSource1">
<Fields>
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
SortExpression="ProductName" />
...
...
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
The question is: Does this SortExpression have any point here?
The GridView and DetailsView uses the BoundField, CommandField, etc. so this is useful for the GridView, but not for the DetailsView. DetailsView is singular in form as it only shows one record at a time so sorting wouldn’t be beneficial to expose.
HTH.