使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();
            }
        }
    }

posted @ 2008-09-21 19:14  郑希强  阅读(738)  评论(0编辑  收藏  举报