在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
aspx.cs文件 protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this.lblNoPage.Text = "1"; this.GridViewBind(); } } /// <summary> /// 分页代码(开始)///////////////////////////// /// </summary> private void GridViewBind() { int curPage = Convert.ToInt32(this.lblNoPage.Text.Trim()); Class1 cl = new Class1();///////////////////////////////SQL类 DataSet ds = cl.selchengshi();//////////////////////////查询语句 PagedDataSource ps = new PagedDataSource(); string totalBar = ds.Tables[0].Rows.Count.ToString().Trim(); this.lblTotalBar.Text = totalBar; ps.DataSource = ds.Tables[0].DefaultView; ps.AllowPaging = true; ps.PageSize = Convert.ToInt32(this.ddlBarPage.SelectedValue.ToString().Trim()); this.lkbPrevious.Enabled = true; this.lkbNext.Enabled = true; this.lkbHome.Enabled = true; this.lkbLast.Enabled = true; ps.CurrentPageIndex = curPage - 1; int nobar = curPage * ps.PageSize; this.lblNoBar.Text = nobar.ToString().Trim(); if (curPage == 1) { this.lkbPrevious.Enabled = false; this.lkbHome.Enabled = false; } if (curPage == ps.PageCount) { this.lkbNext.Enabled = false; this.lkbLast.Enabled = false; this.lblNoBar.Text = totalBar; } this.lblTotalPage.Text = (ps.PageCount).ToString().Trim(); this.ddlSearchPage.Items.Clear(); for (int i = 1; i < ps.PageCount + 1; i++) this.ddlSearchPage.Items.Add(i.ToString().Trim()); if (Convert.ToInt32(this.lblNoPage.Text.Trim()) - 1 >= this.ddlSearchPage.Items.Count) { this.ddlSearchPage.SelectedIndex = 0; ps.CurrentPageIndex = 0; this.lblNoPage.Text = "1"; this.lkbPrevious.Enabled = false; this.lkbHome.Enabled = false; this.lkbNext.Enabled = false; this.lkbLast.Enabled = false; if (Convert.ToInt32(totalBar) <= Convert.ToInt32(this.ddlBarPage.SelectedValue.ToString().Trim())) this.lblNoBar.Text = totalBar; else { this.lblNoBar.Text = ddlBarPage.SelectedValue.ToString().Trim(); this.lkbNext.Enabled = true; this.lkbLast.Enabled = true; } } else this.ddlSearchPage.SelectedIndex = Convert.ToInt32(this.lblNoPage.Text.Trim()) - 1; this.RepeaterDate.DataSource = ps; this.RepeaterDate.DataBind(); } //首页 protected void lkbHome_Click(object sender, EventArgs e) { this.lblNoPage.Text = "1"; this.GridViewBind(); } //上一页 protected void lkbPrevious_Click(object sender, EventArgs e) { this.lblNoPage.Text = Convert.ToString(Convert.ToInt32(this.lblNoPage.Text.Trim()) - 1); this.GridViewBind(); } //下一页 protected void lkbNext_Click(object sender, EventArgs e) { this.lblNoPage.Text = Convert.ToString(Convert.ToInt32(this.lblNoPage.Text.Trim()) + 1); this.GridViewBind(); } //尾页 protected void lkbLast_Click(object sender, EventArgs e) { this.lblNoPage.Text = lblTotalPage.Text.Trim(); this.GridViewBind(); } //选择第几页 protected void ddlSearchPage_SelectedIndexChanged(object sender, EventArgs e) { this.lblNoPage.Text = this.ddlSearchPage.SelectedItem.Text.Trim(); this.GridViewBind(); } //一页显示多少条 protected void ddlBarPage_SelectedIndexChanged(object sender, EventArgs e) { this.lblNoPage.Text = "1"; this.GridViewBind(); } ///分页代码(结束)/////////////////////////
aspx文件 <div> <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" style="FONT-SIZE: 12px;LINE-HEIGHT: 20px;COLOR: #000000;"> <tr> <td bgcolor="#d4d1ca" style="width:50%;" align="center">名称</td> <td bgcolor="#d4d1ca" style="width:50%;" align="center">详细</td> </tr> </table> </div> <div> <asp:Repeater ID="RepeaterDate" runat="server"> <ItemTemplate> <table width="100%"> <tr> <td bgcolor="#eaeaea" style="width:50%;word-break:break-all" align="center"> <asp:Label ID="lblName" runat="server" Text='<%#("Name") %>'></asp:Label></td> <td bgcolor="#eaeaea" style="width:50%;word-break:break-all" align="center"> <asp:Label ID="lblconete" runat="server" Text='<%#("Content") %>'></asp:Label></td> </tr> </table> </ItemTemplate> </asp:Repeater> <div> <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" style="FONT-SIZE: 12px;LINE-HEIGHT: 20px;COLOR: #000000;"> <tr> <td bgcolor="#d4d1ca"> <table width="100%"> <tr> <td align="left"><strong> <asp:Label ID="lblNoBar" runat="server" Text="0"></asp:Label>/<asp:Label ID="lblTotalBar" runat="server" Text="0"></asp:Label>条, <asp:DropDownList ID="ddlBarPage" runat="server" OnSelectedIndexChanged="ddlBarPage_SelectedIndexChanged" > <asp:ListItem Value="10" Text="10" Selected="true"></asp:ListItem> <asp:ListItem Value="20" Text="20"></asp:ListItem> <asp:ListItem Value="30" Text="30"></asp:ListItem> <asp:ListItem Value="40" Text="40"></asp:ListItem> <asp:ListItem Value="50" Text="50"></asp:ListItem> </asp:DropDownList>条/页, <asp:Label ID="lblNoPage" runat="server" Text="0"></asp:Label>/<asp:Label ID="lblTotalPage" runat="server" Text="0"></asp:Label>页</strong> </td> <td align="right"><strong> <asp:LinkButton ID="lkbHome" runat="server" OnClick="lkbHome_Click">首页</asp:LinkButton> | <asp:LinkButton ID="lkbPrevious" runat="server" OnClick="lkbPrevious_Click" >上一页</asp:LinkButton> | <asp:LinkButton ID="lkbNext" runat="server" OnClick="lkbNext_Click">下一页</asp:LinkButton> | <asp:LinkButton ID="lkbLast" runat="server" OnClick="lkbLast_Click">尾页</asp:LinkButton> <asp:DropDownList ID="ddlSearchPage" runat="server" OnSelectedIndexChanged="ddlSearchPage_SelectedIndexChanged" > </asp:DropDownList> </strong> </td> </tr> </table> </td> </tr> </table> </div> </div> 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kenriy/archive/2010/04/13/5481647.aspx
|
请发表评论