DataGrid Sorting - bidirectional

  • Thread starter Thread starter Snig
  • Start date Start date
S

Snig

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.
 
I'd say it is not a normal requirement. You have some work to do here. First
of all, you can catch the double click and differentiate it from the single
click using javascript client side. It would be a little messy to move that
double click to the server side just like the single click which is mapped
by default. I suggest you convert your code to sort the datagrid client
side. You can then customize the grid to sort based on the either the single
click or the double click. Here is a link to sorting a datagrid client side.
Hopefully, you can put the two together. Before you go converting code,
research to see whether or not you can map a double click to a code behind.
I don't know if it can be done and frankly, I haven't seen it either, but
it's worth a shot.
http://v4cnet.europe.webmatrixhosting.net/repeater/test_repeater.aspx
 
try this

protected string SortField

{

get

{

object o = ViewState["SortField"];

return (o == null) ? "": (String)o;

}

set

{

ViewState["SortField"] = value;

}

}

private void dg1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)

{

dg1.CurrentPageIndex = 0;

if(SortField.EndsWith(" DESC"))

{

SortField = e.SortExpression;;

}

else

{

if(SortField == e.SortExpression)

SortField = e.SortExpression + " DESC";

else

SortField = e.SortExpression;

}

BindGrid();

}
 
Back
Top