使Repeater中实现行交替颜色
前台
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<table>
<tr id="row" runat="server">
<td>
<%#DataBinder.Eval(Container.DataItem,"title")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
后台程序
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
int i = e.Item.ItemIndex;
if (i % 2 == 0)
{
HtmlTableRow row = (HtmlTableRow)e.Item.FindControl("row");
if (row != null)
{
row.BgColor = System.Drawing.Color.Black.ToString();
}
}
}