从标签ID更改整个gridview单元格颜色 [英] Change entire gridview cell color from label ID
问题描述
尝试弄清楚当我具有标签ID时如何更改gridview单元格的背景颜色.
Trying to figure out how to change the background color of a gridview cell when I have the label ID.
<ItemTemplate>
<asp:Label ID="thisLabel" runat="server" Text='<%# Bind("thisLabel") %>'></asp:Label>
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="thisLabel" runat="server" Text='<%# Bind("thisLabel") %>'></asp:Label>
</ItemTemplate>
Label lbStdPrice = (Label)e.Row.FindControl("lbStdPrice");
lbPrice.BackColor = System.Drawing.Color.Yellow;
Label lbStdPrice = (Label)e.Row.FindControl("lbStdPrice");
lbPrice.BackColor = System.Drawing.Color.Yellow;
这仅突出显示文本.我希望它更改整个单元格的颜色,例如:
This only highlights the text. I want it to change entire cell color like:
e.Row.Cells[10].BackColor = System.Drawing.Color.LimeGreen;
推荐答案
您可以将父级转换回TableCell并更改颜色.
You can cast the parent back to a TableCell and change the color.
Label lbStdPrice = (Label)e.Row.FindControl("thisLabel");
TableCell cell = lbStdPrice.Parent as TableCell;
cell.BackColor = Color.LimeGreen;
这篇关于从标签ID更改整个gridview单元格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!