Repeater method to display separators at intervals between multiple lines. As shown in the picture
This example uses vs.net 2008 (C#) to write the background .CS code. From 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><p class=\"sep\"></p><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; }
Frontend.aspx code
<form id="form1" runat="server"> <p> <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> </p> </form>
Download code example: PageDemo.RAR
Related documents: Paging implementation of Repeater control Repeater control implements editing, updating, and deletion operations Repeater
is used nested in RepeaterThe above is the detailed content of Repeater method to display separators at intervals between multiple lines. For more information, please follow other related articles on the PHP Chinese website!