c# - 从标签 ID 更改整个 gridview 单元格颜色

标签 c# asp.net .net gridview

当我有标签 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/

相关文章:

jquery - 这个界面元素的名称是什么?指示幻灯片/页面的位置

c# - Server.MapPath 和 HostingEnvironment.MapPath 有什么区别?

c# - 如何从 mysql 数据库列在 C# 中的组合框中添加选项

C# 在数组中保存对字符串变量的引用

c# - 使用 asp.net 验证器就足够了吗?

c# - ASP.NET 中用户控件和页面的通用基类

c# - Lambda Func<> 和 Fluent

php - 如何开发CRM系统

c# - 如何重叠两个控件

c# - .NET Core 2.1 Web API 是否支持基于约定的路由?