Click here to Skip to main content
15,896,040 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
when i user upload image and display at datalist i have mention my code at below.
and after display image i want mouse over at all images.
so, how can i do ?



my code is:

ASP.NET
<asp:DataList ID="DataList1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84"
            BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" GridLines="Both"
            RepeatColumns="3">
            <footerstyle backcolor="#F7DFB5" forecolor="#8C4510" />
            <itemstyle backcolor="#FFF7E7" forecolor="#8C4510" />
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <SelectedItemTemplate>
            </SelectedItemTemplate>
            <itemtemplate>
                <table style="width: 100%;">
                    <tr>
                        <td rowspan="3">
                            <img alt="" src='Admin/ProductImages/<%# Eval("ImageName") %>' />
                        </td>
                        <td>
                        </td>
                        <td>
                             
                        </td>
                    </tr>
                </table>
            </itemtemplate>
Posted
Updated 10-May-17 5:05am
v2

1 solution

It's easy with jQuery:

HTML
<html>
<head>
    <title> ... </title>
    <script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
</head>
<body>

	<img alt="Image" id="image" />	
	
	<script type="text/javascript">

                $(document).ready(function() {
			imageElement = $("#image"); // element img found by its attribute id="image"
			imageElement.attr("src", "small.png"); // start with small image
			imageElement.hover(
				function() { // mouse moves over the image
					$(this).attr("src", "big.png");
				},
				function() { // mouse goes out
					$(this).attr("src", "small.png");
				}
			);
		});
        
        </script>

</body>
</html>


I assume you have two images: "small.png" and "big.png", basically, both could be made from the same source image, but "small.png" was re-sampled down to smaller size with same aspect ratio.

It works, tested.

If you need to learn jQuery, please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^],
http://docs.jquery.com/Tutorials:How_jQuery_Works[^],
http://docs.jquery.com/Tutorials[^].

—SA
 
Share this answer
 
v2
Comments
Maciej Los 6-Jun-12 18:12pm    
Good answer, my 5!
Sergey Alexandrovich Kryukov 6-Jun-12 18:25pm    
Thank you, Maciej.
--SA
SoMad 6-Jun-12 18:28pm    
Nice and simple answer. When I read the question, I remembered a jQuery plugin I ran into - I think it looks really cool, but I have not had a reason to use it yet: www.wizzud.com/jqdock/demonstrator[^]

Soren Madsen
Sergey Alexandrovich Kryukov 6-Jun-12 18:33pm    
Thank you, Soren.

I see, the page you have shown is some more advanced example, but also server-side code (via Ajax, I did not look thoroughly) could be involved: the image could be scaled on-the fly by the server side to provide smooth size gradation, save on images on disk and work and waste some traffic (which is a general problem of extensive post-backs and Ajax).

The sufficient reason to use jQuery is elegance, laconic code style and readability it promotes, even for the same effects you already has before.
--SA
thatraja 6-Jun-12 21:48pm    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900