By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,689 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,689 IT Pros & Developers. It's quick & easy.

DataGrid Multiple SortExpressions

P: n/a
A DataGrid control displays records from a SQL Server 2005 DB table.
The AllowSorting property of the DataGrid has been set to True & the
SortExpressions of the BoundColumns have been set to the different
columns so that users can sort the DataGrid by clicking the headers in
the DataGrid. The DataGrid can be sorted using all the headers in the
DataGrid except for the first column header.

<asp:DataGrid ID="dg1" AllowSorting="true" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="COL1">
<ItemTemplate>
<%# Container.DataItem("Col1") %>
</ItemTemplate>
</asp:TemplateColumn>

<asp:BoundColumn DataField="Col2" HeaderText="COL2"
SortExpression="Col2"/>
<asp:BoundColumn DataField="Col3" HeaderText="COL3"
SortExpression="Col3"/>
<asp:BoundColumn DataField="Col4" HeaderText="COL4"
SortExpression="Col4"/>

<asp:EditCommandColumn...../>
</Columns>
</asp:DataGrid>

In order to sort the DataGrid, I am binding the DataGrid to a DataView
so that I can use the DataView's Sort property. Unfortunately, the
above code sorts the DataGrid based on only one column i.e. the SQL
query would look something like this:

SELECT * FROM MyTable ORDER BY Col2 ASC

I need to sort the DataGrid based on multiple columns so that if 2
records under the Col2 column happen to be identical, the DataGrid
would then be sorted based on some other column, say, Col3 i.e. the SQL
query should look something like this:

SELECT * FROM MyTable ORDER BY Col2 ASC, Col3 DESC

Is there anyway by which the DataGrid can be sorted based on 2 or more
sort expressions?

Nov 30 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.