jQuery replacing an image inside a .net datalist

Posted by user359409 on Stack Overflow See other posts from Stack Overflow or by user359409
Published on 2010-06-05T21:27:02Z Indexed on 2010/06/05 21:32 UTC
Read the original article Hit count: 168

Filed under:
|
|

(submit said I was trying to post an image so I've changed image everywhere to ix I am trying to get jQuery to replace an ix inside a datalist. The original ix is the thumbnail ix of a product on a category page. The small ix I am clicking on are swatch ix for the different colors of a product. I can get it to work using a div tag around the ix tag inside the ItemTemplate. I don't need to use a div tag if I can get the imagesx to swap- I was just using it because that is sample code I found and it works for the first product in the category.

                 <asp:HyperLink ID="ProductNav" runat="server" NavigateUrl='<%#Eval("NavigateUrl") %>'>
                 <div id="ladiv" runat="server">
                 <asp:Ixx runat="server" ID="ProdThumb" />
                 </div>
                 </asp:HyperLink>
                <asp:PlaceHolder ID="phSwatches" runat="server"></asp:PlaceHolder>

The ProdThumb ix is added from the code behind and the swatches are added from the code behind

                 swatches.Controls.Add(new LiteralControl("<table><tr>"));
                    foreach(OptionChoice optionChoice in option.Choices)
                    {
                        string swatchThumbnail = string.Format("<ix ID=\"{0}\" src=\"{1}\"  border=\"0\" class=\"{2}\" />","swatch" + optionChoice.OptionChoiceId.ToString(), ResolveUrl(optionChoice.ThumbnailUrl),"imgthumb");
                        swatches.Controls.Add(new LiteralControl("<td>"));
                        swatches.Controls.Add(new LiteralControl(swatchThumbnail));
                        swatches.Controls.Add(new LiteralControl("</td>"));
                    }
                    swatches.Controls.Add(new LiteralControl("</tr></table>"));

                prodThumb.IxUrl = product.ThumbnailUrl;
                prodThumb.AlternateText = product.ThumbnailAltText;
                prodThumb.CssClass = "Thumbnail";

The jQuery is: $(function() { $("ix.imgthumb").click(function(e) { var t = $(this); var newImg = ''; $('#ladiv') .html($(newImg) ); }); });

 </script>

Both images are named similar, except the swatch contains "sws" and the larger one is the some only with "swl". I have spent several days searching but am not able to get it to work. If I try something like $("#<%=ladiv.ClientID %>") the code can't find it. I appreciate any help.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about jQuery