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

OnMouseOver and listview items

2 Answers 136 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jure
Top achievements
Rank 1
Jure asked on 21 Dec 2010, 12:42 PM
Hey!

I am using a RadListView. Every item contains just one Image button like this:

<ItemTemplate>
    <fieldset style="float: left; width: 270px; height: 110px;">
        <div>
            <asp:ImageButton ID="imgCategory" runat="server" OnClick="imgCategory_Click" OnDataBinding="imgCategory_DataBind"
CommandArgument='<%# Eval("CategoryId") %>'/>
        </div>
     </fieldset>
</ItemTemplate>

I load the ImageButtons dynamacily in the codebehind, now I would like to change the Image source (ImageUrl) on MouseOver and on MouseOut is that possible.

Do you have any different solution in your mind?

Thanks for your asistance.

Sincerely, Jure

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Dec 2010, 01:05 PM
Hello Jure,


One suggestion is accessing the control in ItemDatabound event and attaching the OnMuseOver and OnMiouseOut event to image control. Pass the imageUrl and image control (passing 'this' as parameter) to the client handler.
Accessing Controls in RadListView

Now in the client-side event handler, set the imageurl based on the url passed.


-Shinu.
0
Jure
Top achievements
Rank 1
answered on 21 Dec 2010, 02:21 PM
I've done it like this:

protected void imgCategory_DataBind(object sender, EventArgs e)
        {
            ImageButton img = (ImageButton)sender;
string urlOver = "over";
string urlOut = "out";
img.Attributes.Add("OnMouseOver", "javascript:ImgBtnMouseOut(" + urlOver + ");");
            img.Attributes.Add("OnMouseOut", "javascript:ImgBtnMouseOver(" + urlOut + ");");
}  

then i have javascript:

function ImgBtnMouseOver(url) {
            alert("testOver");
        }

        function ImgBtnMouseOut(url) {
            alert("testOut");
        }
function ImgBtnMouseOver(url) {
            alert("testOver");
        }
 
        function ImgBtnMouseOut(url) {
            alert("testOut");
        }

And it doens't work, but if I add javascript functions without parameters:

img.Attributes.Add("OnMouseOver", "javascript:ImgBtnMouseOut();");
img.Attributes.Add("OnMouseOut", "javascript:ImgBtnMouseOver();");

Now it works...

What am I missing here?


Tags
ListBox
Asked by
Jure
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jure
Top achievements
Rank 1
Share this question
or