首页 > 代码库 > Repeater分页
Repeater分页
后台代码
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { //如果Repeater1容器中控件的类型等于列表控件中的页脚类型则执行 if (e.Item.ItemType == ListItemType.Footer) { //初始化一个HyperLink类(超链接文字)的新实例。//搜索当前命名容器(Repeater1控件)中带指定id("hlfir")参数的控件 //e.Item.FindControl("hlfir")从Repeater1中搜索所有控件找id为hlfir的控件 HyperLink Index = (HyperLink)e.Item.FindControl("hlfir"); HyperLink Top = (HyperLink)e.Item.FindControl("hlp"); HyperLink Down = (HyperLink)e.Item.FindControl("hln"); HyperLink wei = (HyperLink)e.Item.FindControl("hlw"); //n为总页数 int n = Convert.ToInt32(GetRepeater().PageCount); //i为当前页的索引 int i = Convert.ToInt32(GetRepeater().CurrentPageIndex); if (i <= 0) { Index.Enabled = false; Top.Enabled = false; Down.Enabled = true; } else { //单击超链接时应导航到的Url Top.NavigateUrl = "?page=" + (i - 1); } if (i >= n - 1) { Index.Enabled = true; Top.Enabled = true; Down.Enabled = false; wei.Enabled = false; } else { Down.NavigateUrl = "?page=" + (i + 1); } //首页 Index.NavigateUrl = "?page=0"; //尾页 wei.NavigateUrl = "?page=" + (n - 1); } }
前台代码
<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand" onitemdatabound="Repeater1_ItemDataBound"> <HeaderTemplate> <table width = "100%"> <tr> <td> 商品名称 </td> <td> 商品系列 </td> <td> 商品图片 </td> <td> 商品价格 </td> <td> 详细信息 </td> <td> 商品备注 </td> <%--<td> 商品管理 </td>--%> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# Eval("wName") %> </td> <td> <%# Eval("wSet") %> </td> <td> <img id = "im" src = http://www.mamicode.com/‘<%# Eval("wImage") %>‘ style = " width:100px;height:100px;" alt = "无法显示" /> </td> <td> <%# Eval("wPrice") %> </td> <td> <%# Eval("wMinuteNews")%> </td> <td> <%# Eval("wBak") %> </td> <%--<td>--%> <%--<input id="Button1" type="button" value=http://www.mamicode.com/"添加商品" /><br /> <input id = "delete" type ="button" value = http://www.mamicode.com/"删除商品" /><br /> <%--<%# "<a href = http://www.mamicode.com/‘WareAlter.aspx?wID=" + Eval("wID") + "‘>修改商品</a>"%><br />--%> <%--<asp:LinkButton ID="LinkButton1" runat="server" CommandName = "add" CommandArgument = ‘<%# Eval("wID") %>‘>添加商品</asp:LinkButton><br /> <asp:LinkButton ID="LinkButton2" runat="server" CommandName = "alter" CommandArgument = ‘<%# Eval("wID") %>‘>修改商品</asp:LinkButton><br /> <asp:LinkButton ID="LinkButton3" runat="server" CommandName = "delete" CommandArgument = ‘<%# Eval("wID") %>‘>删除商品</asp:LinkButton>--%> <%--</td>--%> </tr> </ItemTemplate> <FooterTemplate> <tr> <td colspan="2" style="font-size:10pt;color:#0099ff; background-color:#e6feda;"> <asp:HyperLink ID="hlfir" runat="server" Text = "首页"></asp:HyperLink> <asp:HyperLink ID="hlp" runat="server" Text = "上一页"></asp:HyperLink> <asp:HyperLink ID="hln" runat="server" Text = "下一页"></asp:HyperLink> <asp:HyperLink ID="hlw" runat="server" Text = "尾页"></asp:HyperLink> </td> </tr> </table> </FooterTemplate> </asp:Repeater>
Repeater分页
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。