gridview的sort_Gridview分页后排序

Gridview 点击排序字段, 对分页后的数据根据排序字段进行升降排序

GridView 我用的是默认分页 , 排序的代码如下:

protected void gvResult_Sorting(object sender, GridViewSortEventArgs e)

{

GridView gv = (GridView)sender;

SortOrder = SortOrder == "asc" ? "desc" : "asc";

SortColumn = e.SortExpression;

ViewState["sortstr"] = SortColumn + " " + SortOrder;

DataTable dt = ViewState["dt"] as DataTable;

DataCount = dt.Rows.Count;

DataView dv = new DataView(dt);

gv.DataSource = dv;

if (ViewState["sortstr"] != null && ViewState["sortstr"].ToString().Length > 0)

dv.Sort = ViewState["sortstr"].ToString();

gv.DataBind();

}

protected void gvResult_Sorted(object sender, EventArgs e)

{

GridView gv = (GridView)sender;

for (int i = 0; i < gv.Columns.Count; i++)

if (gv.Columns[i].SortExpression == SortColumn)

gv.HeaderRow.Cells[i].Controls.Add(new Literal() { Text = SortOrder == "asc" ? "↑" : "↓" });

}

int DataCount

{

get

{

var obj = ViewState["DataCount"];

if (obj != null)

return (int)obj;

return 0;

}

set

{

ViewState["DataCount"] = value;

}

}

string SortOrder

{

get

{

var obj = ViewState["SortOrder"];

if (obj != null)

return (string)obj;

return "asc";

}

set

{

ViewState["SortOrder"] = value;

}

}

string SortColumn

{

get

{

var obj = ViewState["SortColumn"];

if (obj != null)

return (string)obj;

return string.Empty;

}

set

{

ViewState["SortColumn"] = value;

}

}

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

打赏
文章很值,打赏犒劳作者一下
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页

打赏

weixin_39559119

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者