DataGrid Sorting - bidirectional

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.
 
A

Alvin Bruney

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
 
I

Infant Newbie

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();

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top