在业务里先把数据分好组,然后用两个Repeater 嵌套,
protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (((e.Item.ItemIndex + 1) % 3 == 0 && (e.Item.ItemIndex + 1) % 2 != 0))
{
e.Item.Controls.Add(new LiteralControl("</ul>\n<ul class='even'>"));
}
if ((e.Item.ItemIndex + 1) % 3 == 0 && (e.Item.ItemIndex + 1) % 2 == 0)
{
e.Item.Controls.Add(new LiteralControl("</ul>\n<ul class='odd'>"));
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<!--新闻列表开始-->
<div id="newslist">
<asp:Repeater ID="Repeater1" runat="server" EnableViewState="False"
onitemcreated="Repeater1_ItemCreated">
<HeaderTemplate><ul class="odd"></HeaderTemplate>
<ItemTemplate>
<li> <%#Eval("title") %></li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
</div>
<!--新闻列表结束-->
</body>
</html>
嵌套。两个Repeater进行嵌套。然后用数据源进行联动绑定。
1 <asp:Repeater ID="Repeater1" runat="server">
2 <ItemTemplate>
3 <ul>
4 <asp:Repeater ID="childRpt" runat="server" DataSourceID="ObjectDataSource1">
5 <ItemTemplate>
6 <li></li>
7 </ItemTemplate>
8 </asp:Repeater>
9 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>
10 </ul>
11 </ItemTemplate>
12 </asp:Repeater>
so easy
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# Container.ItemIndex % 3 == 0 ? "<ul><li>" : "<li>"%>
<%#Eval("title")%></li>
<%# Container.ItemIndex % 3 == 2 ? "</ul>" : ""%>
</ItemTemplate>
<FooterTemplate>
<%#Repeater1.Items.Count % 3 == 0 ? "" : "</ul>"%>
</FooterTemplate>
</asp:Repeater>
呵呵 好方法呀