Skip to content Skip to sidebar Skip to footer

Gridview Imagebutton Change Image On Mouseover And Mouseout

I have Gridview in which I have an Imagebutton. It shows the image based on hfComplete (a hiddenfield) value. If the value is true, it shows 'images/completeiconfixed.png' and att

Solution 1:

You may get the behavior that you want by setting onmouseover and onmouseout in both cases:

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';");
        }
    }
}

Post a Comment for "Gridview Imagebutton Change Image On Mouseover And Mouseout"