从标签ID更改整个gridview单元格颜色 [英] Change entire gridview cell color from label ID

查看:101
本文介绍了从标签ID更改整个gridview单元格颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试弄清楚当我具有标签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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆