标签:
翻页函数
private PagedDataSource GetPageNumber(List<Comments> list, int pagesize, string gonumber) { // 数据源 PagedDataSource Pgds = new PagedDataSource(); // Pgds.DataSource = list; // 设置允许分页 Pgds.AllowPaging = true; // 每页显示为6行 Pgds.PageSize = pagesize; // 显示总共页数 // lblTotalPage.Text = Pgds.PageCount.ToString(); // 当前页 int CurrentPage; // 请求页码为不为null设置当前页,否则为第一页 if (Request.QueryString["Page"] != null) { CurrentPage = Convert.ToInt32(Request.QueryString["Page"]); } else { CurrentPage = 1; } // 当前页所引为页码-1 Pgds.CurrentPageIndex = CurrentPage - 1; // 显示当前页码 lblCurrentPage.Text = CurrentPage.ToString(); //共多少条 LabelCount.Text = list.Count.ToString(); // 如果不是第一页,通过参数Page设置上一页为当前页-1,否则不显示连接 if (!Pgds.IsFirstPage) { // Request.CurrentExecutionFilePath为当前请求虚拟路径 gonumber = Convert.ToString(CurrentPage - 1); lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + gonumber; } // End If // 如果不是最后一页,通过参数Page设置下一页为当前页+1,否则不显示连接 if (!Pgds.IsLastPage) { // Request.CurrentExecutionFilePath为当前请求虚拟路径 gonumber = Convert.ToString(CurrentPage + 1); lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + gonumber; } return Pgds; }
按钮事件
protected void ButtonNumber_Click(object sender, EventArgs e) { int i = 0; string gonumber = TextBoxNumber.Text.Trim(); if (int.TryParse(gonumber, out i)) { Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + gonumber); } }
前台代码
<div class="widget-footer"> 当前页:<asp:Label ID="lblCurrentPage" runat="server" Text=""></asp:Label> | 总页数:<asp:Label ID="lblTotalPage" runat="server" Text=""></asp:Label> | 共:<asp:Label ID="LabelCount" runat="server" Text=""></asp:Label> 条 | <asp:HyperLink ID="lnkPrev" runat="server">上一页</asp:HyperLink> | <asp:HyperLink ID="lnkNext" runat="server">下一页</asp:HyperLink> | <asp:TextBox ID="TextBoxNumber" runat="server" MaxLength="2" Width="20px"></asp:TextBox> <asp:Button class="btn" ID="ButtonNumber" runat="server" Text="Go" OnClick="ButtonNumber_Click" /> </div>
标签:
原文地址:http://www.cnblogs.com/500k/p/4774249.html