GridView Cell Color
I have to fill the cells of a gridview with just color. No text is required in this case. I have a List of Object X 's that I will bind to gridview. Object X has properties that correspond to the grid view. Suppose there is a property called Y in Object X that is a boolean , if Y is false I need to fill the cell with Red and if Y is true I need to fill it with Yellow.
How do I go about doing this ??
I tried something like this:
<asp:TemplateField>
<HeaderTemplate>Default</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Default"
runat="server"
BackColor= '<%# Eval("Default") %>==true:Green:Blue'
</asp:Label>
</ItemTe开发者_Python百科mplate>
</asp:TemplateField>
It gives me an error saying the server tag is not well formed.
NOTE: I don't need to fill any text in the cell. Just color based on properties of Object X that are boolean.
Hope I have made myself clear..
Any ideas and suggestions are greatly appreciated !
Use the style property:
If( ObjectX.Y){
DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Red
} else {
Data GridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Yellow
}
Not sure if there is a property for forecolor also.
精彩评论