欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Repeater怎么实现多行间隔显示分隔符

程序员文章站 2024-02-28 11:53:40
复制代码 代码如下: protected void page_load(object sender, eventargs e) { if (!page.ispostback...
复制代码 代码如下:

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>