This is a migrated thread and some comments may be shown as answers.

How to change image in MouseOver Event in the Row of RadGrid?

2 Answers 377 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eduardo Chiletto
Top achievements
Rank 1
Eduardo Chiletto asked on 22 Nov 2010, 05:57 PM
Hi!

I need to make the image of an ImageButton in a ColumnTemplate  placed on the grid is replaced by another when  the MouseOver event occurrs. 

Somebody help-me?

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Nov 2010, 06:31 AM
Hello,
If you want to change the image OnRowMouseOver, then attach the OnRowMouseOver event and try out the following client side code.

JavaScript:
<script type="text/javascript">
    function OnRowMouseOver(sender, args)
    {
        var i = args._itemIndexHierarchical;
        var MasterTable = sender.get_masterTableView();
        var image = MasterTable.get_dataItems()[i].findElement("ImbBtn");
        image.src = '../Images/ANTON.jpg';
    }
    function OnRowMouseOut(sender, args)
   {
        var i = args._itemIndexHierarchical;
        var MasterTable = sender.get_masterTableView();
        var image = MasterTable.get_dataItems()[i].findElement("ImbBtn");
        image.src = '../Images/tabSelected.jpg';
    }   
</script>

And if you want change the image on mouse hovering the image itself, then the following code will be helpful.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           ImageButton img = (ImageButton)item.FindControl("ImbBtn");
           img.Attributes.Add("onmouseover", "this.src='../Images/ANTON.jpg'");
           img.Attributes.Add("onmouseout", "this.src='../Images/tabSelected.jpg'");
       }
   }

Thanks,
Princy.
0
Eduardo Chiletto
Top achievements
Rank 1
answered on 23 Nov 2010, 01:56 PM
Thanks, Princy.

It was exactly what I needed.
Tags
Grid
Asked by
Eduardo Chiletto
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Eduardo Chiletto
Top achievements
Rank 1
Share this question
or