使用SQL的pubs任意表做例表
要求实现分页
共XX记录 X页/共X页 上一页 下一页 到_ 页要求代码详细
.ASPX
.CS页面
赏100分

解决方案 »

  1.   

    先去下一个aspnetpager.dll加进bin文件中
              
      <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>          <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="500px" FirstPageText="第一页" LastPageText="最后一页" NextPageText="下一页" PrevPageText="上一页" Font-Names="Arial" BackColor="#E8E8AC" AlwaysShow="true"  ShowInputBox="Always" SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" Font-Size="10pt"></webdiyer:AspNetPager>
      

  2.   

    绑定数据  
    pager pg=new pager();
    public void BindGrid()
        {
             id= Request.QueryString["Aid"];
            //查询表中编号为id的文章评论数据
             string sqlStr = "select * from LeaveWordList order by PublishDate desc"; //where 1=1 and Aid="+id+"and Auditing=0;
            //查询表中编号为id的文章的评论总数
             string sqlstr = "select count(*) from LeaveWordList";// where 1=1 and Aid="+id+" and Auditing =0 ;
            //表名
            string tablename="LeaveWordList";
            this.AspNetPager1.RecordCount = Int32.Parse(pg.GetAllCount(sqlstr).ToString());
            int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
            //每页显示数据数
            int pageSize = this.AspNetPager1.PageSize = 5;
            DataList1.DataSource = pg.GetCurrentPage(sqlStr, pageIndex, pageSize,tablename);
            DataList1.DataBind();
        }aspnetpager数据变化事件
     protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid();
        }
      

  3.   


    类如下:  public class PageContraler
        {
            public static void BeginClick(GridView gv)
            {
                gv.PageIndex = 0;
            }
            public static void EndClick(GridView gv)
            {
                gv.PageIndex = gv.PageCount;
            }
            public static void PreClick(GridView gv)
            {
                gv.PageIndex = gv.PageIndex - 1;
            }
            public static void NextClick(GridView gv)
            {
                gv.PageIndex = gv.PageIndex + 1;
            }
            public static void GoClick(GridView gv, string tb)
            {
                int i = 0;
                try
                {
                    i = int.Parse(((TextBox)gv.BottomPagerRow.Cells[0].FindControl(tb)).Text);
                }
                catch (System.FormatException)
                {
                    //Response.Write("<script language:javascript>alert('您输入的不是数字')</script>");
                    return;
                }
                if (i > 0 && i < (gv.PageCount + 1))
                {
                    gv.PageIndex = i - 1;
                }        }
            public static void GetLabelShow(GridView gv, string lb, string btPre,string btBegin, string btNext,string btEnd, string tb)
            {
                //LABEL框的显示
                ((Label)gv.BottomPagerRow.Cells[0].FindControl(lb)).Text
                        = "当前:" + (gv.PageIndex + 1).ToString() + "页/共" + gv.PageCount.ToString() + "页";
                //设置上一页按钮
                if (gv.PageIndex == 0)
                {
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btPre)).Visible = false;
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btBegin)).Visible = false;
                }
                else
                {
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btPre)).Visible = true;
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btBegin)).Visible = true;
                }
                //设置下一页按钮
                if (gv.PageIndex == gv.PageCount)
                {
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btNext)).Visible = false;
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btEnd)).Visible = false;
                }
                else
                {
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btNext)).Visible = true;
                    ((LinkButton)gv.BottomPagerRow.Cells[0].FindControl(btEnd)).Visible = true;
                }
                //
                ((TextBox)gv.BottomPagerRow.Cells[0].FindControl(tb)).Text = (gv.PageIndex + 1).ToString();        }
        }cs 如下:   protected void btn_pir_Click(object sender, EventArgs e)
        {
            PageContraler.PreClick(GridView1);
             get();         
             
        }
        protected void btn_next_Click(object sender, EventArgs e)
        {
            PageContraler.NextClick(GridView1);
            get();
        }
        protected void Button14_Click(object sender, EventArgs e)
        {
            PageContraler.GoClick(GridView1, "tb_go");
            get();
        }
        private void GetLabelShow()
        {
            PageContraler.GetLabelShow(GridView1, "lb_show", "btn_pir", "btn_begin", "btn_next", "btn_end", "tb_go");
        }    protected void Button15_Click(object sender, EventArgs e)
        {
            get1();
            GridView1.DataSource = ds.Tables[0]; 
            GridView1.DataBind();
            GetLabelShow();    }
        protected void btn_begin_Click(object sender, EventArgs e)
        {
            PageContraler.BeginClick(GridView1);
            get();
        }
        protected void btn_end_Click(object sender, EventArgs e)
        {
            PageContraler.EndClick(GridView1);
            get();
        }aspx 如下:    <asp:Panel ID="Panel111" runat="server" Width="900px" ScrollBars="Horizontal">
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="2500px" CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="15">
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerTemplate>  
                    <asp:LinkButton ID="btn_begin" runat="server" OnClick="btn_begin_Click">第一页</asp:LinkButton>
                    <asp:LinkButton ID="btn_pir" runat="server" Text="上一页" Width="46px" OnClick="btn_pir_Click" />
                    <asp:Label ID="lb_show" runat="server" ></asp:Label>
                    <asp:TextBox ID="tb_go" runat="server" Width="26px"></asp:TextBox>
                    <asp:LinkButton ID="Button14" runat="server" OnClick="Button14_Click" Text="GO" Width="29px" />
                    <asp:LinkButton ID="btn_next" runat="server"  Text="下一页" Width="48px" OnClick="btn_next_Click" />
                    <asp:LinkButton ID="btn_end" runat="server" OnClick="btn_end_Click">最后页</asp:LinkButton>
                </PagerTemplate>
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <EditRowStyle BackColor="#999999" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>
            </asp:Panel>
      

  4.   

    pager里面的
        private SqlConnection con;
        public void Open()
        {
            if (con == null)
                con = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServices"].ConnectionString);
            if (con.State == ConnectionState.Closed)
                con.Open();
        }    //创建一个命令对象并返回该对象
        public SqlCommand CreateCommand(string sqlStr)
        {
            Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sqlStr;
            cmd.Connection = con;
            return cmd;
        }    //生成一个对象并返回该结果集第一行第一列
        public object GetScalar(string sqlStr)
        {
            SqlCommand cmd = CreateCommand(sqlStr);
            object obj = cmd.ExecuteScalar();
            //CommadnBehavior.CloseConnection是将于DataReader的数据库链接关联起来  
            //当关闭DataReader对象时候也自动关闭链接
            return obj;
        }
        //执行数据库查询并返回一个数据集 [当前页码,每页记录条数]
        public DataSet GetCurrentPage(string sqlStr, int pageIndex, int pageSize,string tablename)
        {
            //设置导入的起始地址
            int firstPage = pageIndex * pageSize;        SqlCommand cmd = CreateCommand(sqlStr);
            DataSet dataset = new DataSet();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
            dataAdapter.Fill(dataset, firstPage, pageSize,tablename);
            cmd.Dispose();
            Close();
            dataAdapter.Dispose();
            return dataset;
        }
        //获得查询数据的总条数
        public object GetAllCount(string sqlstr)
        {        object obj = GetScalar(sqlstr);
            return obj;
        }    //关闭数据库
        public void Close()
        {
            if (con != null)
            {
                con.Close();
            }
        }    //释放资源
        public void Dispose()
        {
            if (con != null)
            {
                con.Dispose();
                con = null;
            }
        }
      

  5.   

    get()是重新绑定数据的get1()是获取数据集dataset 放在一个静态变量dataset里 这样点击翻页的时候就无需重新查询数据库
      

  6.   

    http://topic.csdn.net/u/20090113/16/cac6480c-84ff-4ae3-8fa1-11cfa39fd8ea.html
      

  7.   


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    public partial class Page : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {          
                bind();            
            }
        }
        int pageCount;//总页数
        int currentPage=1;//第定义当前页
        void bind()
        {        SqlConnection conn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=jijunwu;");
            string sqlStr = "select * from authors";
            SqlDataAdapter sda = new SqlDataAdapter(sqlStr,conn);
            DataSet ds = new DataSet();
            sda.Fill(ds,"pro");
            //创建数据源
            PagedDataSource pds=new PagedDataSource();
            pds.DataSource = ds.Tables["pro"].DefaultView;
            //允许分页
            pds.AllowPaging = true;
            //设置每页显示记录数
            pds.PageSize = int.Parse(this.DropDownList1.SelectedItem.Value);
            //获取总页数
            pageCount = pds.PageCount;
            this.Label1.Text = pageCount.ToString();
            pds.CurrentPageIndex = currentPage-1;
            //当前页
            this.Label2.Text = Convert.ToString(currentPage);        //数据绑定
            this.GridView1.DataSource = pds;
            this.GridView1.DataBind();
            this.DataList1.DataSource = pds;
            this.DataList1.DataBind();
            this.Repeater1.DataSource = pds;
            this.Repeater1.DataBind();
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            bind();
        }
        /// <summary>
        /// 第一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {//如果当前不是第一页的时候
            if (this.Label2.Text == "1")
            {        }
            else
            {
                currentPage = 1;            
                bind();
            }
        }
        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button2_Click(object sender, EventArgs e)
        {//如果当前不是最后页的时候
            if (this.Label1.Text == this.Label2.Text)
            {
            }
            else
            {          
                currentPage = int.Parse(this.Label2.Text)+1;
                this.Label2.Text = currentPage.ToString();
                bind();
            }
        }
        /// <summary>
        /// 上一页 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button3_Click(object sender, EventArgs e)
        {//如果当前不是第一页的时候
            if (this.Label2.Text != "1")
            {
                currentPage = int.Parse(this.Label2.Text) - 1;
                this.Label2.Text = currentPage.ToString();
                bind();
            }        
        }
        /// <summary>
        /// 最后一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button4_Click(object sender, EventArgs e)
        {//如果当前不是最后一页的时候
            if (this.Label1.Text != this.Label2.Text)
            {
                this.Label2.Text = this.Label1.Text;
                currentPage = int.Parse(this.Label2.Text);
                bind();
            }
        }
    }
      

  8.   

    效果 如图
    实现了三大数据绑定控件的分页
    源:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page.aspx.cs" Inherits="Page" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>三大数据绑定控件分页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        
        <center>
            每页显示记录数:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
                <asp:ListItem>10</asp:ListItem>
                <asp:ListItem>20</asp:ListItem>
                <asp:ListItem>30</asp:ListItem>
                <asp:ListItem>40</asp:ListItem>
            </asp:DropDownList>
            总页数:<asp:Label ID="Label1" runat="server"></asp:Label>
            当前第:<asp:Label ID="Label2" runat="server"></asp:Label>页</center>
            <center>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="第一页" />
                <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="下一页" />
                <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="上一页" />
                <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="最后一页" />
            </center>
            <center>
            GridView控件
            <asp:GridView ID="GridView1" runat="server" Width="313px">
            </asp:GridView>
            DataList控件
            <asp:DataList ID="DataList1" runat="server" Width="793px">
            <HeaderTemplate>
                 <table width="85%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td width="16%">au_id</td>
        <td width="15%">au_lname</td>
        <td width="15%">au_fname</td>
        <td width="24%">phone</td>
        <td width="16%">address</td>
        <td width="10%">city</td>
        <td width="1%">state</td>
        <td width="1%">zip</td>      
        <td width="1%">contract</td>    
      </tr>
            </HeaderTemplate>
            <ItemTemplate>
       
      <tr>
        <td ><%#Eval("au_id") %></td>
        <td ><%#Eval("au_lname")%></td>
        <td ><%#Eval("au_fname")%></td>
        <td ><%#Eval("phone")%></td>
        <td ><%#Eval("address")%></td>
        <td ><%#Eval("city")%></td>
        <td ><%#Eval("state")%></td>
        <td ><%#Eval("zip")%></td>      
        <td ><%#Eval("contract")%></td>   
      </tr>        </ItemTemplate>
            <FooterTemplate>
            </table>
            </FooterTemplate>
            </asp:DataList>
            Repeater控件
            <asp:Repeater ID="Repeater1" runat="server">
             <HeaderTemplate>
                 <table width="85%" border="1" cellspacing="0" cellpadding="0">
      <tr>
       <td width="16%">au_id</td>
        <td width="15%">au_lname</td>
        <td width="15%">au_fname</td>
        <td width="24%">phone</td>
        <td width="16%">address</td>
        <td width="10%">city</td>
        <td width="1%">state</td>
        <td width="1%">zip</td>      
        <td width="1%">contract</td>    
      </tr>
            </HeaderTemplate>
            <ItemTemplate>
       
      <tr>
       <td ><%#Eval("au_id") %></td>
        <td ><%#Eval("au_lname")%></td>
        <td ><%#Eval("au_fname")%></td>
        <td ><%#Eval("phone")%></td>
        <td ><%#Eval("address")%></td>
        <td ><%#Eval("city")%></td>
        <td ><%#Eval("state")%></td>
        <td ><%#Eval("zip")%></td>      
        <td ><%#Eval("contract")%></td>  
      </tr>        </ItemTemplate>
            <FooterTemplate>
            </table>
            </FooterTemplate>
            </asp:Repeater>
            </center>
        </form>
    </body>
    </html>
      

  9.   

    http://www.cnblogs.com/liulanglang/archive/2007/08/12/852321.html
      

  10.   


      //页面跳转
        protected void Button5_Click(object sender, EventArgs e)
        {
            currentPage = Convert.ToInt32(this.TextBox1.Text);
            bind();
        }源代码下载地址  这里
      

  11.   


    Asp.Net DataList 分页的完整代码.cs 代码private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    PageSize = 10;
    sql="select * from products order by all_time desc ";
    if(!Page.IsPostBack)
    {
    //计算总共有多少记录 
    RecordCount = CalculateRecord(); 
    //计算总共有多少页
    //取整 
    PageCount = RecordCount/PageSize; 
    if (RecordCount%PageSize > 0) 
    PageCount = PageCount + 1; 
    lblPageCount.Text = PageCount.ToString(); 
    lblRecordCount.Text = RecordCount.ToString(); 
    ViewState["PageCount"] = PageCount; 
    CurrentPage = 0; 
    ViewState["PageIndex"] = 0; 
    //绑定 
    ListBind();}
    }
    public int CalculateRecord() 

    int intCount; 
    string strCount = "select count(*) as co from products"; 
    SqlConnection Con=new SqlConnection(data.constr);
    SqlCommand addCommand=new SqlCommand(strCount,Con);
    addCommand.Connection.Open();
    SqlDataReader dr;
    dr=addCommand.ExecuteReader();
    if(dr.Read()) 

    intCount = Int32.Parse(dr["co"].ToString()); 

    else 

    intCount = 0; 

    dr.Close(); 
    return intCount; 
    }ICollection CreateSource() 
    {int StartIndex; 
    //设定导入的起终地址 
    StartIndex = CurrentPage*PageSize; 
    string strSel = "select * from products"; 
    SqlConnection Con=new SqlConnection(data.constr);
    DataSet ds = new DataSet(); 
    SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,Con); 
    MyAdapter.Fill(ds,StartIndex,PageSize,"products"); 
    return ds.Tables["products"].DefaultView; 

    public void ListBind() 

    dl1.DataSource = CreateSource(); 
    dl1.DataBind(); 
    lbnNextPage.Enabled = true; 
    lbnPrevPage.Enabled = true; 
    if(PageCount==0) 

    lblCurrentPage.Text = "0"; 
    lbnNextPage.Enabled = false; 
    lbnPrevPage.Enabled = false; 

    else 

    if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false; 
    if(CurrentPage==0) lbnPrevPage.Enabled = false; 
    lblCurrentPage.Text = (CurrentPage+1).ToString(); 


    public void Page_OnClick(Object sender,CommandEventArgs e) 

    CurrentPage = (int)ViewState["PageIndex"]; 
    PageCount = (int)ViewState["PageCount"]; 
    string cmd = e.CommandName; 
    //判断cmd,以判定翻页方向 
    switch(cmd) 

    case "next": 
    if(CurrentPage<(PageCount-1)) CurrentPage++; 
    break; 
    case "prev": 
    if(CurrentPage>0) CurrentPage--; 
    break;
    case "first":
    CurrentPage=0;
    break;
    case "last":
    CurrentPage=PageCount-1;
    break;
    }ViewState["PageIndex"] = CurrentPage;ListBind();}
    HTML 部分:<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="540" border="0">
    <TR>
    <TD align="right">共<asp:label id="lblRecordCount" runat="server">Label</asp:label>条记录  
    共<asp:label id="lblPageCount" runat="server">Label</asp:label>页 当前第<asp:label id="lblCurrentPage" runat="server">Label</asp:label>页 
    <asp:linkbutton id="lbnFirstPage" runat="server" CommandName="first" OnCommand="Page_OnClick">首页</asp:linkbutton> 
    <asp:linkbutton id="lbnPrevPage" CommandName="prev" OnCommand="Page_OnClick" Runat="server">上一页</asp:linkbutton>  
    <asp:linkbutton id="lbnNextPage" runat="server" CommandName="next" OnCommand="Page_OnClick">下一页</asp:linkbutton> 
    <asp:linkbutton id="lbnLastPage" runat="server" CommandName="last" OnCommand="Page_OnClick">尾页</asp:linkbutton></TD>
    </TR>
    </TABLE>
      

  12.   

    OleDbConnection con =new OleDbConnection("Provider=Microsoft.Jet.OleDB.4.0;" + "Data Source="+Server.MapPath("~/DataBase/DB.mdb")); 
    con.Open(); 
    OleDbDataAdapter da = new OleDbDataAdapter(你的SQL语句,con); 
    DataSet ds = new DataSet(); 
    da.Fill(ds,"News"); 
    //创建分页类 
    PagedDataSource objPage = new PagedDataSource(); 
    //设置数据源 
    objPage.DataSource = ds.Tables["News"].DefaultView; 
    //开启分页 
    objPage.AllowPaging = true; 
    //显示显示的行数 
    objPage.PageSize = 20; 
    //定义变量保存当前页索引 
    int curPage; 
    //判断当前页是否有跳转请求 
    if (Request.QueryString["Page"] != null) 
    curPage = Convert.ToInt32(Request.QueryString["Page"]); 
    else 
    curPage = 1; 
    objPage.CurrentPageIndex = curPage - 1; 
    this.Label1.Text = curPage.ToString(); 
    this.Label2.Text = objPage.PageCount.ToString(); 
    if (!objPage.IsFirstPage) 
    { //定义"上一页"超级连接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引植 this.HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?name=" + Request.QueryString["name"]+"&Page="+Convert.ToString(curPage - 1); 

    if (!objPage.IsLastPage) 

    //下一页 
    this.HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?name=" + Request.QueryString["name"]+"&Page="+Convert.ToString(curPage + 1); 

    this.HyperLink3.NavigateUrl = Request.CurrentExecutionFilePath + "?name=" + Request.QueryString["name"]+"&Page=" + Convert.ToString(objPage.PageCount); 
    this.DataList1.DataSource = objPage; 
    this.DataList1.DataBind();Asp.net提供了三个功能强大的列表控件:DataGrid、DataList和Repeater控件,但其中只有DataGrid控件提供分页功能。相对DataGrid,DataList和Repeater控件具有更高的样式自定义性,所以很多时候我们喜欢使用DataList或Repeater控件来显示数据。 
    实现DataList或Repeater控件的分页显示有几种方法: 
    1、写一个方法或存储过程,根据传入的页数返回需要显示的数据表(DataTable) 
    2、使用PagedDataSource类(位于System.Web.UI.WebControls命名空间里) 本篇文章主要说怎么使用PagedDataSource类实现DataList和Repeater控件的分页显示。DataGrid控件内部也使用了PagedDataSource类,PagedDataSource 类封装 DataGrid 控件的属性,这些属性使 DataGrid 可以执行分页。 PagedDataSource 类的部分公共属性: 
    AllowCustomPaging 获取或设置指示是否启用自定义分页的值。 
    AllowPaging 获取或设置指示是否启用分页的值。 
    Count 获取要从数据源使用的项数。 
    CurrentPageIndex 获取或设置当前页的索引。 
    DataSource 获取或设置数据源。 
    DataSourceCount 获取数据源中的项数。 
    FirstIndexInPage 获取页中的第一个索引。 
    IsCustomPagingEnabled 获取一个值,该值指示是否启用自定义分页。 
    IsFirstPage 获取一个值,该值指示当前页是否是首页。 
    IsLastPage 获取一个值,该值指示当前页是否是最后一页。 
    IsPagingEnabled 获取一个值,该值指示是否启用分页。 
    IsReadOnly 获取一个值,该值指示数据源是否是只读的。 
    IsSynchronized 获取一个值,该值指示是否同步对数据源的访问(线程安全)。 
    PageCount 获取显示数据源中的所有项所需要的总页数。 
    PageSize 获取或设置要在单页上显示的项数。 
    VirtualCount 获取或设置在使用自定义分页时数据源中的实际项数。 这些属性是否和DataGrid的属性很相似?没错,DataGrid控件就是使用PagedDataSource类来实现数据分页显示的 。下面举个使用PagedDataSource类实现DataList和Repeater控件的分页显示的例子: 
    public void Page_Load(Object src,EventArgs e) 

    OleDbConnection objConn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\test.mdb"); 
    OleDbDataAdapter objCommand=new OleDbDataAdapter("select * from Users",objConn); 
    DataSet ds=new DataSet(); 
    objCommand.Fill(ds); //对PagedDataSource 对象的相关属性赋值 
    PagedDataSource objPds = new PagedDataSource(); 
    objPds.DataSource = ds.Tables[0].DefaultView; 
    objPds.AllowPaging = true; 
    objPds.PageSize = 5; 
    int CurPage; //当前页面从Page查询参数获取 
    if (Request.QueryString["Page"] != null) 
    CurPage=Convert.ToInt32(Request.QueryString["Page"]); 
    else 
    CurPage=1; objPds.CurrentPageIndex = CurPage-1; 
    lblCurrentPage.Text = "Page: " + CurPage.ToString(); if (!objPds.IsFirstPage) 
    lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1); if (!objPds.IsLastPage) 
    lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1); //把PagedDataSource 对象赋给Repeater控件 
    Repeater1.DataSource=objPds; 
    Repeater1.DataBind(); 
    }
      

  13.   

    DataList分页
    前台代码:
    ------
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="News_test" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 752px; POSITION: absolute; TOP: 16px; HEIGHT: 312px" cellSpacing="0" cellPadding="0" width="752" border="0">
                <TR>
                    <TD style="HEIGHT: 29px"><FONT face="宋体">DataList分页技术和超级链接</FONT></TD>
                </TR>
                <TR>
                    <TD style="HEIGHT: 252px">
                    <asp:datalist id="DataList1" runat="server" Width="576px" Height="96px">
                         <HeaderTemplate>
                                定单编号<td>
                                员工编号<td>
                                定单日期<td>
                                运费<td>
                                运往所在城市
                         </HeaderTemplate>                     <ItemTemplate>
                            <%# DataBinder.Eval(Container.DataItem,"OrderID")%> <td>
                            <%# DataBinder.Eval(Container.DataItem,"CustomerID")%> <td>
                            <%# DataBinder.Eval(Container.DataItem,"OrderDate")%> <td>
                            <%# DataBinder.Eval(Container.DataItem,"Freight")%>  <td>
                            <%# DataBinder.Eval(Container.DataItem,"ShipCity")%>
                         </ItemTemplate>
                     </asp:datalist>
                     </TD>
                    </TR>
                    <TR>
                        <TD><FONT face="宋体">            <asp:linkbutton id="FirstLB" runat="server" OnCommand="LinkButton_Click" CommandName="first">第一页</asp:linkbutton>&nbsp;
                <asp:linkbutton id="PreviousLB" runat="server" OnCommand="LinkButton_Click" CommandName="prev">上一页</asp:linkbutton>&nbsp;
                <asp:linkbutton id="NextLB" runat="server" OnCommand=LinkButton_Click CommandName="next">下一页</asp:linkbutton>&nbsp;
                <asp:linkbutton id="EndLB" runat="server" OnCommand=LinkButton_Click CommandName="end">最后一页</asp:linkbutton>&nbsp;&nbsp;
                总<asp:label id="TotalLbl" runat="server"></asp:label>页 当前第<asp:label id="CurrentLbl" runat="server"></asp:label>页
                <asp:linkbutton id="JumpLB" runat="server" OnCommand=LinkButton_Click CommandName="jump">跳到</asp:linkbutton>第
                <asp:textbox id="TextBox1" runat="server" Width="90px"></asp:textbox>
                页</FONT></TD>
                </TR>
                </TABLE>
        </div>
        </form>
    </body>
    </html>
    -------------------------------------------------
    后台代码:
    ----------
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class News_test : System.Web.UI.Page
    {
        int CurrentPage;//当前页数
        int PageSize;   //每页条数
        int PageCount;  //总页数
        int RecordCount;//总条数
        private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            PageSize = 10;//每页10条记录
                   if (!Page.IsPostBack)
            {            
                 CurrentPage = 0;//当前页习惯设为0
                ViewState["PageIndex"] = 0;//页索引也设为0
                //计算总共有多少记录
                RecordCount = CalculateRecord();
                //计算总共有多少页
                if (RecordCount % PageSize == 0)
                {
                    PageCount = RecordCount / PageSize;
                }
                else
                {
                    PageCount = RecordCount / PageSize + 1;
                }             this.TotalLbl.Text = PageCount.ToString();//显示总页数
                ViewState["PageCount"] = PageCount;//会话session 对整个 application 有效 ,而视图状态 viewstate相当于某个页面的 session            this.DataListBind();//不可以放在初始化条件之前就绑定,那样的话,如果仅有一页的数据,“下一页”页仍然显示
                
            }
        }
        //计算总共有多少条记录
        private int CalculateRecord()
        {
            try
            {
                int recordCount;
                SqlConnection con = new SqlConnection("server=127.0.0.1;database=Northwind;uid=sa;pwd=sa");//数据库使用Northwind;
                con.Open();            string sql = "select count(*) as count from Orders";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataReader sdr = cmd.ExecuteReader();            if (sdr.Read())
                {
                    recordCount = Int32.Parse(sdr["count"].ToString());                
                }
                else
                {
                    recordCount = 0;
                }            sdr.Close();
                con.Close();
                return recordCount;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        //将数据绑定到Datalist控件
        public void DataListBind()
        {
            try
            {
                int StartIndex = CurrentPage * PageSize;//设定导入的起终地址
                string sql = "select * from Orders";
                DataSet ds = new DataSet();
                SqlConnection con = new SqlConnection("server=127.0.0.1;database=Northwind;uid=sa;pwd=sa");
                con.Open();            SqlDataAdapter sda = new SqlDataAdapter(sql, con);
                sda.Fill(ds, StartIndex, PageSize, "orders");//这是sda.Fill方法的第一次重载,里面的变量分别是数据集DataSet ,开始记录数StartRecord,最大的记录数MaxRecord,数据表名TableName
                this.DataList1.DataSource = ds.Tables["orders"].DefaultView;
                this.DataList1.DataBind();
                this.PreviousLB.Enabled = true;
                this.NextLB.Enabled = true;
                if (CurrentPage == (PageCount - 1)) this.NextLB.Enabled = false;//当为最后一页时,下一页链接按钮不可用
                if (CurrentPage == 0) this.PreviousLB.Enabled = false;//当为第一页时,上一页按钮不可用
                this.CurrentLbl.Text = (CurrentPage + 1).ToString();//当前页数        }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }  
        public void LinkButton_Click(Object sender, CommandEventArgs e)//自己编写的按钮点击事件
        {
            CurrentPage = (int)ViewState["PageIndex"];//获得当前页索引
            PageCount = (int)ViewState["PageCount"];//获得总页数
            string cmd = e.CommandName;        //判断cmd,以判定翻页方向
            switch (cmd)
            {
                case "prev"://上一页
                    if (CurrentPage > 0) CurrentPage--;
                    break;            case "next":
                    if (CurrentPage < (PageCount - 1)) CurrentPage++;//下一页
                    break;            case "first"://第一页
                    CurrentPage = 0;
                    break;            case "end"://最后一页
                    CurrentPage = PageCount - 1;
                    break;            case "jump"://跳转到第几页
                    if (this.TextBox1.Text.Trim() == "" || Int32.Parse(this.TextBox1.Text.Trim()) > PageCount)//如果输入数字为空或超出范围则返回
                    {
                        return;
                    }
                    else
                    {                    
                        CurrentPage = Int32.Parse(this.TextBox1.Text.ToString()) - 1;
                        break;
                    }
            }
            ViewState["PageIndex"] = CurrentPage;//获得当前页        this.DataListBind();//重新将DataList绑定到数据库
        }}
      

  14.   

    6楼沙比,没看见人家要的是datalist的分页?