R
rn5a
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.
<aspataGrid 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>
</aspataGrid>
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?
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.
<aspataGrid 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>
</aspataGrid>
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?