Gridview ImageButton在鼠标hover和鼠标移动时更改图像
我有Gridview,其中有一个Imagebutton。 它显示基于hfComplete(隐藏字段)值的图像。
如果值为true,则显示“images / completeiconfixed.png”并将属性附加到onmouseover“this.src =’images / completeiconfixed_transparant.png’;”
如果为false,则显示“images / completeiconfixed_transparant.png”并将该属性附加到onmouseout“this.src =’images / completeiconfixed.png’;”
到目前为止它只是第一次正常工作。 它可以很好地加载图像,当我第一次鼠标hover时它会改变图像,但第二次没有。
任何想法如何使它在每个鼠标上都能正常工作。 我的代码是吼叫。
<asp:ImageButton ID="imgComplete" runat="server" CommandName="completeRecord" CommandArgument='' Height="16px" Width="16px"/> protected void grdNetwork_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ImageButton imgComplete = (ImageButton)e.Row.FindControl("imgComplete"); if (Convert.ToBoolean(hfCompleted.Value) == true) { imgComplete.ImageUrl = "images/completeiconfixed.png"; imgComplete.Attributes.Add("onmouseover", "this.src='images/completeiconfixed_transparant.png';"); } else { imgComplete.ImageUrl = "images/completeiconfixed_transparant.png"; imgComplete.Attributes.Add("onmouseout", "this.src='images/completeiconfixed.png';"); } } }
提前致谢。
在这两种情况下,您可以通过设置onmouseover
和onmouseout
来获得所需的行为:
protected void grdNetwork_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ImageButton imgComplete = (ImageButton)e.Row.FindControl("imgComplete"); if (Convert.ToBoolean(hfCompleted.Value)) { imgComplete.ImageUrl = "images/completeiconfixed.png"; imgComplete.Attributes.Add("onmouseover", "this.src='images/completeiconfixed_transparant.png';"); imgComplete.Attributes.Add("onmouseout", "this.src='images/completeiconfixed.png';"); } else { imgComplete.ImageUrl = "images/completeiconfixed_transparant.png"; imgComplete.Attributes.Add("onmouseover", "this.src='images/completeiconfixed.png';"); imgComplete.Attributes.Add("onmouseout", "this.src='images/completeiconfixed_transparant.png';"); } } }