Change Color of a Column Based on Column Values http://www.c-sharpcorner.com/Code/2003/May/ChangeDataGridColumnColor.asp
<asp:datagrid id="" ....> <Columns> <asp:TemplateColumn HeaderText="租售类型"> <ItemTemplate> <font color ='<%# get_color(databinder.eval(Container.DataItem,"type")) %>'> <%# databinder.eval(Container.DataItem,"type") %> </font> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid> Function get_color(ByVal mytype) Dim aa As String Select Case mytype Case "出租" aa = "red" Case "求购" aa = "blue" Case Else aa = "yellow" End Select Return aa End Function
http://www.c-sharpcorner.com/Code/2003/May/ChangeDataGridColumnColor.asp
<Columns>
<asp:TemplateColumn HeaderText="租售类型">
<ItemTemplate>
<font color ='<%# get_color(databinder.eval(Container.DataItem,"type")) %>'>
<%# databinder.eval(Container.DataItem,"type") %>
</font>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Function get_color(ByVal mytype)
Dim aa As String
Select Case mytype
Case "出租"
aa = "red"
Case "求购"
aa = "blue"
Case Else
aa = "yellow"
End Select
Return aa
End Function