日期:2014-05-19  浏览次数:20383 次

DataGrid分页
如何在C#.NET中实现DataGrid前后翻10页.

------解决方案--------------------
或参考XproerBBS源码:
你可以下载XproerBBS,已经开源
由于空间比较小我将它上传到了QQ空间上
QQ群号:6259764

两个文件
FoxBBS 论坛源代码
images 论坛图片文件,将它他们解压到同一个目录中

开发环境:Microsoft .NET Framework1.1
语言:C#.NET 1.1
数据库: ACCESS

论坛地址:www.xproer.com/bbs/index.html

说明:
由于论坛项目是使用我本地的路径,所以如果下载下来后直接打开项目的话可能会出现路径错误


我本地设置如下
c:\wwwroot\FoxBBS\

朋友们下载后最好能建一个FoxBBS 文件夹,然后将 FoxBBS 时面的所有文件解决到 FoxBBS 文件

夹时面

XproerBBS如何后台管理:
http://www.xproer.com/bbs/thread-3-602.aspx
XproerBBS学习教程-数据库配置:
http://www.xproer.com/bbs/thread-3-605.aspx
XproerBBS简介:
http://www.xproer.com/bbs/thread-3-606.aspx
XproerBBS数据表:
http://www.xproer.com/bbs/thread-3-609.aspx
XproerBBS存储过程:
http://www.xproer.com/bbs/thread-3-610.aspx
XproerBBS视图:
http://www.xproer.com/bbs/thread-3-611.aspx
XproerBBS存储过程调用实例:
http://www.xproer.com/bbs/thread-3-612.aspx
XproerBBS文件说明
http://www.xproer.com/bbs/thread-3-613.aspx
XproerBBS文件夹说明:
http://www.xproer.com/bbs/thread-3-614.aspx
------解决方案--------------------
或者通过SQl语句 每次查询十条 显示出来
键值需要计算
每页条数*(所在页数-1)=每页第一条显示的键值

或者通过pagedatasource分页

public void BindData()
{
DataTable dsTable = new DataTable();
PagedDataSource objPag = new PagedDataSource();//添加分页
objPag.DataSource = dsTable[写明邦定的表].DefaultView;
objPag.AllowPaging = true;//允许分页
objPag.PageSize = 5;
int curPage;
if (Request.QueryString[ "Page "] != null)
{
curPage = Int32.Parse(Request.QueryString[ "Page "]);
}
else
{
curPage = 1;
}
objPag.CurrentPageIndex = curPage - 1;//获取当前页的索引
this.Label1.Text = curPage.ToString();//获取第一页
this.Label2.Text = objPag.PageCount.ToString();//获取总的页
//如果当前也不是首页,设置前一页
if (!objPag.IsFirstPage)
{
HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?Page= " + Convert.ToString(curPage - 1);
}
//如果当前的也不是尾页,则设置后页的链接地址
if (!objPag.IsLastPage)
{
HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?Page= " + Convert.ToString(curPage + 1);
}
//首页的链接
HyperLink3.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1 ";
//尾页的链接
HyperLink4.NavigateUrl = Request.CurrentExecutionFilePath + "?Page= " + objPag.PageCount.ToString();
DataList1.DataSource = objPag;
DataList1.DataBind();
}