datalist 不带分页功能的。
你要自己找其他控件来帮助分页。AspNetPager

解决方案 »

  1.   

    HTML:
    ------------------------------------------------------------------
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DataList ID="DataList1" runat="server" Style="position: relative" RepeatDirection="Horizontal" CellPadding="4" ForeColor="#333333" OnItemDataBound="DataList1_ItemDataBound">
                <ItemTemplate>
            <table style="width: 100px; position: relative">
                <tr>
                    <td>
                        <asp:Label ID="lblauid" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_id") %>'></asp:Label></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblaufname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_fname") %>'></asp:Label></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblaucity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"city") %>'></asp:Label></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblauzip" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"zip") %>'></asp:Label></td>
                </tr>
            </table>
                </ItemTemplate>
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <AlternatingItemStyle BackColor="White" />
                <ItemStyle BackColor="#EFF3FB" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <FooterTemplate>
                    <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
                </FooterTemplate>
            </asp:DataList></div>
            <asp:TextBox ID="TextBox1" runat="server" Style="position: relative"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="position: relative"
                Text="填写想分页每页的项个数,并执行" />
        </form>
    </body>
    </html>
      

  2.   

    C#:
    ---------------------------------------------------------
    SqlConnection con;
        SqlDataAdapter da;
        DataSet ds;    public int Pagesize
        {
            get
            {
                return Convert.ToInt32(Session["page"]);
            }
            set
            {
                Session["page"] = value;
            }
        }    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int n=0;
                if (Request.QueryString["page"] != "")
                {
                    n = Convert.ToInt32(Request.QueryString["page"]);
                }
                else
                {
                    n = 0;
                }
                Bind(n);
            }
        }    public void Bind(int n)
        {
            this.DataList1.DataSource = pds(n);
            this.DataList1.DataBind();
        }    public DataSet GetData(string sql)
        {
            con = new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
            da = new SqlDataAdapter(sql,con);
            ds = new DataSet();
            da.Fill(ds);
            return ds;
        }    public PagedDataSource pds()
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = GetData("select * from authors").Tables[0].DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = Pagesize;
            return pds;
        }    public PagedDataSource pds(int n)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = GetData("select * from authors").Tables[0].DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = Pagesize;
            pds.CurrentPageIndex = n;
            return pds;
        }
        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Footer)
            {
                PlaceHolder ph = (PlaceHolder)e.Item.FindControl("ph");
                for (int i = 0; i < pds().PageCount; i++)
                {
                    HyperLink hp = new HyperLink();
                    Literal li = new Literal();                int n = i + 1;
                    hp.ID = n.ToString();
                    hp.Text = n.ToString();
                    hp.NavigateUrl = "?page=" + i.ToString();
                    li.Text = " ";
                    ph.Controls.Add(hp);
                    ph.Controls.Add(li);
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["page"] = Convert.ToInt32(TextBox1.Text);
            Bind(0);
            string str = Request.Url.ToString().Substring(0,21);
            Response.Write(str);
        }
      

  3.   

    上面的代码直接沾过去试试
    连接的库是sqlserver2000中默认的pubs库