分页的问题 定义了一个:PagedDataSource pds = new PagedDataSource(); pds.PageSize = 5;我使用的是DataList控件,绑定的数据库。用什么方法把pds 与DataList关联起来!如何给我绑定的数据分页吗?谢谢~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Data.SqlClient;namespace DataListTest1{ ///<summary> /// WebForm1的摘要说明。 ///</summary> publicclass WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DataList DataList1; protected System.Web.UI.WebControls.HyperLink HlkFirst; protected System.Web.UI.WebControls.HyperLink HlkPrevious; protected System.Web.UI.WebControls.HyperLink HlkNext; protected System.Web.UI.WebControls.HyperLink HlkLast; protected System.Web.UI.WebControls.Label LblTotalRecord; protected System.Web.UI.WebControls.Label LblTotalPages; protected System.Web.UI.WebControls.Label LblCurrent; protected System.Web.UI.WebControls.LinkButton LinkButton1; protected System.Web.UI.WebControls.TextBox TbPageIndex; privatevoid Page_Load(object sender, System.EventArgs e) { //在此处放置用户代码以初始化页面 if(!this.IsPostBack) { this.bindtoGL(); } } //绑定数据到DataList privatevoid bindtoGL() { SqlConnection con=new SqlConnection("server=.;database=Northwind;uid=sa;pwd="); con.Open(); SqlDataAdapter sda=new SqlDataAdapter(); sda.SelectCommand=new SqlCommand("select * from Orders",con); DataSet ds=new DataSet(); sda.Fill(ds,"orders"); PagedDataSource pds=new PagedDataSource(); pds.DataSource=ds.Tables["orders"].DefaultView; pds.AllowPaging=true; pds.PageSize=12; int CurrentPage; if(Request.QueryString["pageIndex"]!=null) { CurrentPage=Convert.ToInt32(Request.QueryString["pageIndex"]); } else { CurrentPage=1; } pds.CurrentPageIndex=CurrentPage-1;//CurrentPageIndex是从0页开始的所以要减1 this.LblCurrent.Text=CurrentPage.ToString();//显示是从第1页开始 //上一页导航 if(!pds.IsFirstPage) this.HlkPrevious.NavigateUrl=Request.CurrentExecutionFilePath+"?pageIndex="+Convert.ToString(CurrentPage-1); //下一页导航 if(!pds.IsLastPage) this.HlkNext.NavigateUrl=Request.CurrentExecutionFilePath+"?pageIndex="+Convert.ToString(CurrentPage+1); //第一页导航 this.HlkFirst.NavigateUrl=Request.CurrentExecutionFilePath+"?pageIndex="+1; //最后一页导航 this.HlkLast.NavigateUrl=Request.CurrentExecutionFilePath+"?pageIndex="+pds.PageCount; this.DataList1.DataSource=pds; this.DataList1.DataBind(); } //这个是最后一页的按钮点击事件 privatevoid LinkButton1_Click(object sender, System.EventArgs e) { SqlConnection con=new SqlConnection("server=.;database=Northwind;uid=sa;pwd="); con.Open(); SqlDataAdapter sda=new SqlDataAdapter(); sda.SelectCommand=new SqlCommand("select * from Orders",con); DataSet ds=new DataSet(); sda.Fill(ds,"orders"); PagedDataSource pds=new PagedDataSource(); pds.DataSource=ds.Tables["orders"].DefaultView; pds.AllowPaging=true; pds.PageSize=12; if(this.TbPageIndex.Text.ToString()==""||Convert.ToInt32(this.TbPageIndex.Text.Trim())>=pds.PageCount) { Response.Write("输入不能为空,或则数字不能超过总页数!"); } else { pds.CurrentPageIndex=Convert.ToInt32(this.TbPageIndex.Text.Trim())-1; } this.LblCurrent.Text=this.TbPageIndex.Text; this.DataList1.DataSource=pds; this.DataList1.DataBind(); } }} sql性能的面试! 怎样实现让根目录下的文件夹'admin'登录之后才能访问,登录的页面放在'admin'中 C#操作word文档要导入那几个命名空间 奇怪的问题!!!! 发布asp.net时,出现 CS0016编译器错误信息,是什么原因!!急 为什么在窗体的FORM中加上RUNAT="server" 窗体的的Javascript就执行出错呢?请高手帮忙啊。 asp access怎么可以不读取空值 如何在C#方法中调用JavaScript方法? 关于asp.net发邮件的问题 为啥不能出错 asp.net怎样做才能像PHP中的smarty那样做模版 一个password field的问题。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货