GridView Sorting 分页

lixinramaxel41658133 2011-01-17 05:26:15
使用GridView的Sorting事件,在分页的时候,点击第二页,之前单击表头呈现的排序效果又没有了。怎么样才能在分页的时候依然能保持之前的排序效果。
...全文
106 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ycproc 2011-01-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]

分页方法需要自己写,不然分页就不能保持排序状态。
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (e.SortExpression != "")
{
if (GridView1.PageCount > 0)
……
[/Quote]

学习
不想整没法 2011-01-18
  • 打赏
  • 举报
回复
你首先在pageload里面定义 一个ViewState["sort"]=""

DataSet ds_todayjzb = tTodayJzbBLL.queryTodayJzbByCondition(condition);
if (ViewState["sort"] == "")
{
ds_todayjzb.Tables[0].DefaultView.Sort = " jzbh desc";
}
else
{
ds_todayjzb.Tables[0].DefaultView.Sort = ViewState["sort"].ToString();
}
gv_todayjzb.DataSource = ds_todayjzb.Tables[0].DefaultView;
gv_todayjzb.DataBind();
心灵彩虹 2011-01-17
  • 打赏
  • 举报
回复
//数据绑定
public void DataBound(string _WhereStr)
{
//防止刷新
if (this.isRefresh())
{
return;
}
if (string.IsNullOrEmpty(_WhereStr))
{
_WhereStr = " 1=1";
}
string aidSelect = "SELECT * from emp,dep where emp.dep_id = dep.dep_id and emp_type = '1' and " + _WhereStr;
DataTable fileTable = new DataTable();
fileTable = DbAccess.GetDS(aidSelect).Tables[0];

if (fileTable.Rows.Count == 0)
{
//Response.Write("<script>alert('没有符合此条件的记录!')</script>");
//DbUITool.JsMsg(this.Page, "没有符合此条件的记录!");
return;
}
else
{
GridView1.DataSource = fileTable;
GridView1.DataBind();
}
this.lblCurrentPage.Text = string.Format("当前第{0}页/总共{1}页", this.GridView1.PageIndex + 1, this.GridView1.PageCount);
}
//GridView分页
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
tiaojian = this.lbtiaojian.Text.Trim();
DataBound(tiaojian);
}
koukoujiayi 2011-01-17
  • 打赏
  • 举报
回复
如果楼主是使用自带的分页,建议楼主使用
SqlDataSource,或者如果分层的话,使用ObjectDataSource,
只要设置一下GridView1.AllowSorting = true;即OK了!
wuyq11 2011-01-17
  • 打赏
  • 举报
回复
分页方法需要自己写,不然分页就不能保持排序状态。
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (e.SortExpression != "")
{
if (GridView1.PageCount > 0)
{
string SortDirection = "ASC";
SortDirection = (this.GridView1.Attributes["SortDirection"].ToString() == SortDirection ? "DESC" : "ASC");
this.GridView1.Attributes["SortExpression"] = e.SortExpression;
this.GridView1.Attributes["SortDirection"] = SortDirection;
//重新绑定数据
DataBind();
}
}
}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧