473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

DataGrid Multiple SortExpressions

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
0 1308

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Simon | last post by:
Can any one please tell me how to set the width of my datagrid coloums after I have put them into edit mode? At the moment I bind the datagrid to a returning dataset; DataGrid1.DataSource =...
7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
1
by: Soul | last post by:
*** I am not sure this question belong to *.languages.csharp or *.framework.windowsdorms.databinding, so I post to both *** Hi, Currently I have a DataGrid which bind to a DataSet. One of...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
12
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
1
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been...
5
by: Vik | last post by:
If there are a few Select buttons in a datagrid, is there a way to distinguish in code which button was clicked? Thanks.
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.