我在ItemTemplate
内的GridView
内有此控件:
<img alt="" style="cursor: pointer" src="images/plus.png" runat="server"
id="img_expand1" />
我需要在条件中将可见性设置为false:
else
{
Image img = (Image)e.Row.FindControl("img_expand1");
img.Visible = false;
}
但是我收到了一个错误:
Invalid cast exception. Impossible to cast object type
'System.Web.UI.HtmlControls.HtmlImage' on type
'System.Web.UI.WebControls.Image'.
我做错了什么?我该如何解决这个问题?
答案 0 :(得分:1)
System.Web.UI.HtmlControls.HtmlImage img = (System.Web.UI.HtmlControls.HtmlImage)e.Row.FindControl("img_expand1");
img.Visible = false;