AspNetPager控件的分页与排序
2016-03-21 10:46
411 查看
终于把AspNetPager控件的分页和排序都整出来了。
分页:按照它的步骤做,改一下具体的方法即可。
遇到难题:点击下一页,总是重新加载页面,这一点很烦人。
解决办法:换成Ajax的局部刷新就好用了。
具体看项目中的代码
排序:这个费了不少了劲
关键是要把排序条件传到DAL中去,而不是在前台中用Dataview中排序。
细节:
<asp:BoundField DataField="I_TranState"
HeaderText="状态" Sortexpression_r="I_TranState">
<HeaderStyle CssClass="bt1" />
<ItemStyle Wrap="False" />
</asp:BoundField>
1.先是在GridView中的绑定列中设置条件:Sortexpression_r="I_TranState"
2.在GridView中的Sorting事件中写代码:
protected
void Repeater_NEWS_Sorting(object sender, GridViewSortEventArgs
e)
{
ViewState["orderName"] =
e.Sortexpression_r;
if (GridViewSortDirection ==
SortDirection.Ascending)
//设置排序方向
{
GridViewSortDirection = SortDirection.Descending;
ViewState["orderId"] = " DESC";
}
else
{
GridViewSortDirection = SortDirection.Ascending;
ViewState["orderId"] = " ASC";
}
gridviewdatabind(ViewState["orderName"].ToString(),
ViewState["orderId"].ToString());
}
为ViewState设置条件,以便于传递到后台。
if和else的意思是:刚开始是:Asc,点击一次排序条件变为Desc,再点一次变回来。
分页:按照它的步骤做,改一下具体的方法即可。
遇到难题:点击下一页,总是重新加载页面,这一点很烦人。
解决办法:换成Ajax的局部刷新就好用了。
具体看项目中的代码
排序:这个费了不少了劲
关键是要把排序条件传到DAL中去,而不是在前台中用Dataview中排序。
细节:
<asp:BoundField DataField="I_TranState"
HeaderText="状态" Sortexpression_r="I_TranState">
<HeaderStyle CssClass="bt1" />
<ItemStyle Wrap="False" />
</asp:BoundField>
1.先是在GridView中的绑定列中设置条件:Sortexpression_r="I_TranState"
2.在GridView中的Sorting事件中写代码:
protected
void Repeater_NEWS_Sorting(object sender, GridViewSortEventArgs
e)
{
ViewState["orderName"] =
e.Sortexpression_r;
if (GridViewSortDirection ==
SortDirection.Ascending)
//设置排序方向
{
GridViewSortDirection = SortDirection.Descending;
ViewState["orderId"] = " DESC";
}
else
{
GridViewSortDirection = SortDirection.Ascending;
ViewState["orderId"] = " ASC";
}
gridviewdatabind(ViewState["orderName"].ToString(),
ViewState["orderId"].ToString());
}
为ViewState设置条件,以便于传递到后台。
if和else的意思是:刚开始是:Asc,点击一次排序条件变为Desc,再点一次变回来。
相关文章推荐
- AspNetPager控件的分页与排序
- Asp.net配置文件中数据库的连接
- asp.net MVC EF Where 过滤条件怎么写
- Asp.net 甘特图数据导出Project(.mpp)文件
- ASP.NET-服务器客户端的信息保持
- asp.net-页面生命周期
- ASP.NET-优化websit
- ASP.NET-Session cooike
- ASP.NET-post、get的区别
- ASP.NET-关于Global.asax的作用
- ASP.NET-POSTBACK是什么
- ASP.NET-入门
- asp.net原理
- ASP.NET Core文章汇总
- ASP.NET5 REST API使用示例——基于云平台+云服务打造自己的在线翻译工具
- Java调用ASP.NET的webservice故障排除
- ASP.NET5 MVC6 连接SQLSERVER
- ASP.NET web 应用程序项目
- ASP.NET 宏观总结
- 关于ASPCMS标签调用的一些总结