AspNetPager控件官方下载地址:http://www.webdiyer.com/aspnetpager/
把控件加到项目中(添加自定义控件的方法),并把它拖放到页面上
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <table> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <tr> <td><%#Eval("ID") %></td> <td><%#Eval("TaskTime") %></td> <td><%#Eval("UName") %></td> </tr> </ItemTemplate> </asp:Repeater> </table> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="true" FirstPageText="首页" LastPageText="尾页" PrevPageText="上一页" NextPageText="下一页" ShowPageIndexBox="Always" PageIndexBoxType="DropDownList" TextBeforePageIndexBox="跳转到" OnPageChanged="AspNetPager1_PageChanged"></webdiyer:AspNetPager> </ContentTemplate> </asp:UpdatePanel>
Page_Load事件
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int recordCount = new VTaskBLL().GetTaskCount("1=1"); AspNetPager1.RecordCount = recordCount; BindReapter(); } }
BindReapter方法
private void BindReapter() { int currentPage = AspNetPager1.CurrentPageIndex; int pageSize = AspNetPager1.PageSize = 10; List<VTaskModel> vtaskList = new VTaskBLL().GetTaskPage(pageSize, currentPage); Repeater1.DataSource = vtaskList; Repeater1.DataBind(); }
翻页事件
protected void AspNetPager1_PageChanged(object sender, EventArgs e) { BindReapter(); }