I have an ASP.NET 2.0 DataGrid, like so:
<asp:DataGrid
runat="server"
ID="_customerTable"
CssClass="gridDisplay"
HeaderStyle-CssClass="headerRow"
AutoGenerateColumns="False"
>
<Columns>
<asp:TemplateColumn HeaderText="First Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "FirstName") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Last Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "LastName") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Address 1">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Address1") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Address 2">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Address2") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
The problem is, I need to set up a cssclass for cells that meet certain criteria in a column. The best I can seem to figure out is a rather ugly method--either specifically doing e.Item.Cells[0]...[3] for each column, or setting ItemStyle-CssClass="firstName"..."address2", and then updating the cssclass for a cell based on my conditions and whether or not the cell's cssclass matches.
This seems like a really ugly solution, though, so I'd far prefer any advice on a better way--if one exists.