By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,905 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,905 IT Pros & Developers. It's quick & easy.

DataGrid Sorting - bidirectional

P: n/a
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.

Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.webmatrixhostin..._repeater.aspx

--
Regards,
Alvin Bruney
Got Tidbits? Get it here
www.networkip.net/tidbits
"Snig" <sn****@yahoo.co.in> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 18 '05 #2

P: n/a
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.DataGridSortCommandEvent Args 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();

}
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.