奇偶行颜色不同设置 如何让GridView的行颜色交替

<asp:GridView
    //奇偶行颜色不同设置 如何让GridView的行颜色交替
    protected void gvwRetailerListRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex % 2 == 0)
            {
                e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#EAFED7");
            }
            else
            {
                e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#FFFFFF");
            }
        }
    }

或用
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Eval("NameEn")%>
</ItemTemplate>
<AlternatingItemTemplate>
<%# Eval("NameEn") %>
</AlternatingItemTemplate>
</asp:TemplateField>                       

<asp:TemplateField>
<ItemTemplate>
<%# Eval("RAddress")%>
</ItemTemplate>
<AlternatingItemTemplate>
<%# Eval("RAddress")%>
</AlternatingItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle CssClass="headerstyle" />
<RowStyle BackColor="Yellow" />

主要是:
<AlternatingRowStyle CssClass="headerstyle" />
<RowStyle BackColor="Yellow" />
这两个给行附颜色用的属性

posted on 2011-06-29 13:13  carekee  阅读(4270)  评论(0编辑  收藏  举报