当我有标签 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;
关于c# - 从标签 ID 更改整个 gridview 单元格颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51390716/