//奇偶行颜色不同设置 如何让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" />
这两个给行附颜色用的属性