萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp.net編程 >> Repeater怎麼實現多行間隔顯示分隔符

Repeater怎麼實現多行間隔顯示分隔符

 本文為大家介紹下Repeater如何實現多行間隔顯示分隔符,下面有個不錯的示例,感興趣的朋友可以參考下

 代碼如下: 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("  ");  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}    <</CODE>form id="form1" runat="server">  <</CODE>div>  <</CODE>asp:Repeater ID="rptList" runat="server"  onitemdatabound="rptList_ItemDataBound">  <</CODE>HeaderTemplate>  <</CODE>ul>  </</CODE>HeaderTemplate>  <</CODE>ItemTemplate>  <</CODE>li>  <</CODE>asp:Literal ID="ltlTitle" runat="server"></</CODE>asp:Literal></</CODE>li>  </</CODE>ItemTemplate>  <</CODE>FooterTemplate>  </</CODE>ul></</CODE>FooterTemplate>  </</CODE>asp:Repea</</CODE>form>   
copyright © 萬盛學電腦網 all rights reserved