GridView控件:捕捉排序方向 [英] Gridview: capturing sort direction
本文介绍了GridView控件:捕捉排序方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UpdatePanel与排序启用GridView和事件处理程序如下:
I have a gridview in an updatepanel with sorting enabled and an event handler as follows:
protected void MyGridSort(object sender, GridViewSortEventArgs e)
{
var TheDirection = (e.SortDirection).ToString();
var TheColumn = (e.SortExpression).ToString();
}
我把一个断点,这些代码行之后。我每次preSS列标题,我的变量TheDirection总是呈现递增。
I put a breakpoint just after these lines. Every time I press the column header, my variable TheDirection is always showing Ascending.
为什么不从上升到下降和背部切换?
Why is it not toggling from ascending to descending and back?
感谢。
推荐答案
您可以保留在ViewState或会话的方向。像这样的(未测试code):
You could keep the direction in the ViewState or the Session. Like this (Untested Code):
protected void MyGridSort(object sender, GridViewSortEventArgs e)
{
var TheDirection = (e.SortDirection).ToString();
var TheColumn = (e.SortExpression).ToString();
string prevColumn = "", prevDirection = "";
if (Session["MyGridSortColumn"] != null)
prevColumn = Session["MyGridSortColumn"].ToString();
if (Session["MyGridSortDirection"] != null)
prevDirection = Session["MyGridSortDirection"].ToString();
if (TheColumn == prevColumn) {
if (prevDirection == "ASC")
TheDirection = "DESC";
else
TheDirection = "ASC";
}
Session["MyGridSortDirection"] = TheDirection;
Session["MyGridSortColumn"] = TheColumn;
}
这篇关于GridView控件:捕捉排序方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文