试图弄清楚当我有标签 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;
您可以将父级强制转换回 TableCell 并更改颜色。
Label lbStdPrice = (Label)e.Row.FindControl("thisLabel");
TableCell cell = lbStdPrice.Parent as TableCell;
cell.BackColor = Color.LimeGreen;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)