Groups | Blog | Home
all groups > asp.net datagrid control > november 2003 >

asp.net datagrid control : DataGrid Sorting - bidirectional


Snig
11/27/2003 12:05:55 PM
Hi,

I want to sort the DataGrid according to the number of clicks of mouse on
the column-header link.
e.g.
if user clicks on the header once - it will be sorted ASC
if the header is double-clicked - it will be sorted DESC

It is not exactly toggling the sorting-order. I have seen a lot of messages
and articles in the web about toggling the sort order (like first time click
will generate ASC sort, next time click will generate DESC sort and so on).

But my requirement is how to catch single/double-click of the mouse on the
column header and fixing the sort order accordingly.

Any ideas ?

Thanx
Snig.

[ MVP ] Sukesh Ashok Kumar
1/3/2004 7:22:17 AM
If you are looking for client side sorting of data in datagrid, check the
example from
http://www.v4cnet.com/

Rgds
Sukesh

[quoted text, click to view]

Prodip Saha
1/5/2004 9:45:33 AM
Very simple:
Add a private variable on the page/class:
private static string SortExpression="";

In your sortcommand event handler add the following codes:

if(SortExpression==e.SortExpression.ToString()) //Change the sort order to
DESC

{

SortExpression = e.SortExpression.ToString() +" DESC";

}

else //Change the sort order to ASC

{

SortExpression = e.SortExpression.ToString();

}

try

{

//Bind the Grid Data

BindGridData();


}

catch(Exception ex)

{

throw ex;

}

Prodip Saha

[quoted text, click to view]

AddThis Social Bookmark Button