【发布时间】:2018-12-25 16:57:39
【问题描述】:
当我有标签 ID 时,试图弄清楚如何更改 gridview 单元格的背景颜色。
<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;
这只会突出显示文本。我希望它改变整个单元格的颜色,例如:
e.Row.Cells[10].BackColor = System.Drawing.Color.LimeGreen;
【问题讨论】:
-
应该可以(你写的最后一行)。您的要求中缺少某些内容。 (不确定“当我有标签 ID 时”是什么意思。)
-
@wazz 对于
e.Row.Cells[10].BackColor,单元格编号是硬编码的。如果网格的布局发生变化,我将不得不更新新的单元格编号。使用标签 ID,布局是否更改无关紧要。这更有意义吗?