ASP.Net常见技术疑难解析(三)
2008-12-04 23:38
246 查看
DataList控件实现分页功能
SqlConnection con = new SqlConnection(Convert.ToString(ConfigurationManager.ConnectionStrings["ConnectionString"]));string conString = "SELECT [CompanyName], [CustomerID] FROM [Reports_Customers] ORDER BY [CustomerID]";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(conString, con);
DataSet ds = new DataSet();
da.Fill(ds);
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = 10;
pds.DataSource = ds.Tables[0].DefaultView;
Int32 totPage, curPage;
totPage = 0;
curPage = 0;
lnkprev.Visible = true;
lnkfirst.Visible = true;
lnknext.Visible = true;
lnklast.Visible = true;
totPage = pds.PageCount;
if (Request.QueryString["Page"] != null)
{
curPage = Convert.ToInt32( Request.QueryString["Page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage - 1;
lbpage.Text = "当前第" + Convert.ToString(curPage) + "页,共" + Convert.ToString(totPage) + "页";
lnkfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=1";
lnklast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + totPage.ToString();
if (!pds.IsFirstPage)
{
lnkprev.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage - 1);
}
else
{
lnkprev.Visible = false;
lnkfirst.Visible = false;
}
if (!pds.IsLastPage)
{
lnknext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage + 1);
}
else
{
lnknext.Visible = false;
lnklast.Visible = false;
}
CustomerList.DataSource = pds;
CustomerList.DataBind();
相关文章推荐
- ASP.Net常见技术疑难解析(一)
- ASP.Net常见技术疑难解析(三)
- ASP.Net常见技术疑难解析(一)
- ASP.Net常见技术疑难解析(四)
- ASP.Net常见技术疑难解析(二)
- ASP.Net常见技术疑难解析(二)
- ASP.Net常见技术疑难解析(四)
- asp.net: GridView相关技术(二--重要事件解析)
- 一起谈.NET技术,ASP.NET缓存全解析6:数据库缓存依赖
- JSP简介以及常见动态网站开发技术(Asp.net、Php、Jsp)
- [ASP.net教程]WPF外包技术分享—WPF的MVVM架构解析(分享)
- YbSoftwareFactory 代码生成插件【九】:基于JQuery、WebApi的ASP.NET MVC插件的代码生成项目主要技术解析
- 基于JQuery、WebApi的ASP.NET MVC插件的代码生成项目主要技术解析
- 转:基于ASP.NET的Comet长连接技术解析
- 基于ASP.NET的Comet长连接技术解析
- 上周技术关注:ASP.NET常见参考项目分析
- 一起谈.NET技术,ASP.NET缓存全解析7:第三方分布式缓存解决方案 Memcached和Cacheman
- 基于ASP.NET的Comet长连接技术解析
- 基于 Asp.Net的 Comet 技术解析
- 庖丁解牛-Asp.net 3.5控件和组件开发技术一常见问题及书中问题纠正贴