How can mouseover work with database's images without preloading?

Last post 08-28-2008 10:40 AM by NC01. 1 replies.

Sort Posts:

  • How can mouseover work with database's images without preloading?

    08-28-2008, 5:39 AM

    Hi

    I have a C# code which retireve image from a local directory and display as a gallery. How can I add mouseover effect on those images without preloading? How can the image file name and mouseover image file name be matched?

    Here is the code:

    public string[] GalleryListing(string localdir)
            {
                ArrayList array = new ArrayList();
                DirectoryInfo dir = new DirectoryInfo(HttpContext.Current.Server.MapPath(@".\" + localdir));
                for (int i = 0; i < search.Length; i++)
                {
                    foreach (FileInfo as in dir.GetFiles(search[i]))
                    {
                        array.Add(@".\" + localdir + @"\" + as.ImageName);
                    }
                }
                return (string[])array.ToArray(typeof(string));
            }

    I use ASP:REPEATER to load the thumbnail images.

    There is no <img src...>

    <ASP:HYPERLINK id="links" runat="server" imageurl="<%# imageURL(Container.ItemIndex) %>" navigateurl="<%# NavigationURL(Container.DataItem) %>" >

    How should I do it?
     

     

    Thanks

  • Re: How can mouseover work with database's images without preloading?

    08-28-2008, 10:40 AM
    Answer
    • All-Star
      75,595 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,090
    • TrustedFriends-MVPs

    Handle the server-side ItemDataBound event of the Repeater and attach the mouse events there.

    aspx file:

    <asp:Repeater id="Repeater1" OnItemDataBound="Repeater1_ItemDataBound" ...

    <script type="text/javascript">
    <!--
    var oldSrcValue = '';
    function mouseOverFunction(elementRef)
    {
     oldSrcValue = elementRef.src;
     elementRef.src = elementRef.mouseoverSrc;
    }
    function mouseOutFunction(elementRef)
    {
     if ( oldSrcValue.length > 0 )
      elementRef.src = oldSrcValue;

     oldSrcValue = '';
    }
    // -->
    </script>

    aspx.cs file:

    void Repeater1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
    {    
     if ( (e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem) )
     {
      HyperLink repeaterHyperLink = (HyperLink)e.Item.FindControl("links");
      if ( repeaterHyperLink != null )
      {
       repeaterHyperLink.Attributes.Add("mouseoverSrc", "'The URL to the mouseover image here'");
       repeaterHyperLink.Attributes.Add("onmouseover", "mouseOverFunction(this);");
       repeaterHyperLink.Attributes.Add("onmouseout", "mouseOutFunction(this);");
      }
     }
    }

    NC...

Page 1 of 1 (2 items)
Microsoft Communities