【发布时间】:2011-10-24 11:33:02
【问题描述】:
protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = (Image)e.Row.FindControl("Status");
int msgid;
int.TryParse(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MsgID")), out msgid);
string status = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MessageActive"));
if(status.Equals("No"))
{
e.Row.BackColor = Color.Red;
}
//Based on some condition I am assigning images to the row
if (value >= Toptarg)
{
img.ImageUrl = "Styles/Images/GreenBox.jpg";
img.ToolTip = "Met Top Target";
img.AlternateText = "Met Top Target";
}
else
{
img.ImageUrl = "Styles/Images/AmberBox.jpg";
img.ToolTip = "In Progress";
img.AlternateText = "In Progress";
}
}
}
我有一个 gridView,它有一个名为 MessageActive 的列,在行数据绑定中,我得到了 messageActive 的值。如果 messageActive 值为“是”,则不需要更改。如果是“否”,我想以红色显示特定行,如何在行数据绑定中设置行背景颜色
网格视图的一些属性
<RowStyle BackColor="White" />
<AlternatingRowStyle BackColor="MistyRose" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#696969" Font-Bold="True" ForeColor="White" />
命名空间 使用 System.Web.UI.WebControls; 使用 System.Drawing;
我收到了这个错误
'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
Source Error:
Line 56: if (e.Row.RowType == DataControlRowType.DataRow)
Line 57: {
Line 58: Image img = (Image)e.Row.FindControl("Status");
Line 59: int msgid;
Line 60: int.TryParse(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MsgID")), out msgid);
【问题讨论】:
-
我通过使用 System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("Status"); 解决了我的错误>
标签: c# asp.net gridview webforms