Repeater多行间隔显示分隔符的方法。如图
本例使用 vs.net 2008(C#)编写后台.CS代码。来自 admin10000.com
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { rptList.DataSource = GetTable(); rptList.DataBind(); } } protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { DataRowView drv = (DataRowView)e.Item.DataItem; Literal ltlTitle = (Literal)e.Item.FindControl("ltlTitle"); ltlTitle.Text = drv.Row["title"].ToString(); if ((e.Item.ItemIndex + 1) % 5 == 0 && (e.Item.ItemIndex + 1) < 15) { System.Web.UI.LiteralControl ul = new LiteralControl("</ul><div class=\"sep\"></div><ul>"); e.Item.Controls.Add(ul); } } } DataTable GetTable() { DataTable dt = new DataTable(); dt.Columns.Add("title", typeof(string)); for (int i = 1; i <= 15; i++) { DataRow row = dt.NewRow(); row["title"] = "这是文章标题 " + i + ""; dt.Rows.Add(row); } return dt; }
前台.aspx代码
<form id="form1" runat="server"> <div> <asp:Repeater ID="rptList" runat="server" onitemdatabound="rptList_ItemDataBound"> <HeaderTemplate> <ul> </HeaderTemplate> <ItemTemplate> <li> <asp:Literal ID="ltlTitle" runat="server"></asp:Literal></li> </ItemTemplate> <FooterTemplate> </ul></FooterTemplate> </asp:Repeater> </div> </form>
下载代码示例: PageDemo.RAR
相关文档: Repeater控件的分页实现 Repeater控件实现编辑、更新、删除操作 Repeater中嵌套使用Repeater
- 本文固定链接: https://zxbcw.cn/post/1932/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)