Default.aspx代码: <body> <form id="form1" runat="server"> <div> <asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <table class="style1" border="3" runat="server"> <tr> <td class="style2" rowspan="4"> <asp:Label ID="lblId" runat="server" Text='<%#Eval("job_id") %>'> </asp:Label> </td> </tr> <tr> <td> <asp:Label ID="lblDesc" runat="server" Text='<%#Eval("job_desc") %>'> </asp:Label> </td> </tr> <tr> <td> <asp:Label ID="lblMin" runat="server" Text='<%#Eval("min_lvl") %>'> </asp:Label> </td> </tr> <tr> <td> <asp:Label ID="lblMax" runat="server" Text='<%#Eval("max_lvl") %>'> </asp:Label> </td> </tr> </table> </ItemTemplate> </asp:DataList> </div> <asp:Label ID="lblCurrent" runat="server"></asp:Label> <asp:Label ID="lblCount" runat="server" Text="/"></asp:Label> <asp:LinkButton ID="lbtnFirst" runat="server" CommandName="First" oncommand="lbtnFirst_Command">首页</asp:LinkButton> <asp:LinkButton ID="lbtnPrev" runat="server" CommandName="Prev" oncommand="lbtnFirst_Command" >上一页</asp:LinkButton> <asp:LinkButton ID="lbtnNext" runat="server" CommandName="Next" oncommand="lbtnFirst_Command">下一页</asp:LinkButton> <asp:LinkButton ID="lbtnLast" runat="server" CommandName="Last" oncommand="lbtnFirst_Command">末页</asp:LinkButton> </form> </body> Default.aspx.cs代码: using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class _Default : System.Web.UI.Page { private DataTable getData_Jobs() { string sql = "select * from jobs"; DBHelper db = new DBHelper(); return db.getDataSet(sql).Tables[0]; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { getData(1); } } static int i; private void getData(int pageIndex) { PagedDataSource pd = new PagedDataSource(); pd.AllowPaging = true; pd.PageSize = 2; pd.CurrentPageIndex = pageIndex - 1; pd.DataSource = getData_Jobs().DefaultView; DataList1.DataSource = pd; DataList1.DataBind(); lblCurrent.Text = Convert.ToString(pd.CurrentPageIndex + 1); lblCount.Text = "/"; lblCount.Text += pd.PageCount.ToString(); i = pd.PageCount; if (pd.IsFirstPage) { lbtnFirst.Visible = false; lbtnPrev.Visible = false; } else { lbtnFirst.Visible = true; lbtnPrev.Visible = true; } if (pd.IsLastPage) { lbtnLast.Visible = false; lbtnNext.Visible = false; } else { lbtnLast.Visible = true; lbtnNext.Visible = true; } } protected void lbtnFirst_Command(object sender, CommandEventArgs e) { switch (e.CommandName) { case "First": getData(1); break; case "Next": getData(Convert.ToInt32(lblCurrent.Text) + 1); break; case "Prev": getData(Convert.ToInt32(lblCurrent.Text) - 1); break; case "Last": getData(i); break; default: getData(1); break; } } }