问题
I am writing an web app in asp.net, I have in my DB URL of my images and I want to display all the images from my DB wrapped with lightbox my code so far is:
<script type="text/javascript" src="Lightbox/js/prototype.js"></script>
<script type="text/javascript" src="Lightbox/js/scriptaculous.js?load=effects,builder> </script>
<script type="text/javascript" src="Lightbox/js/lightbox.js"></script>
<a rel="lightbox" id="userImageLightBox" runat="server" title="profile image">
<img id="userImage" runat="server" width="150" height="146" alt="" src=""/>
</a>
so my question is: how can i insert all my images using foreach from the code behind, that when i click on the image the lightbox will activate
thanks
回答1:
Use a ListView which will give you total control over the markup as well as clean HTML. Use a HttpHandler (other Q's on SO on this topic - do a search) to retrieve image from DB and serve it up.
In your ListView, use ItemTemplates to contain markup for each image. Images can be obtained by using the following syntax for each img source attribute.
src='ImageHandler.ashx?imageID=<%# Eval("ImageName")%>'
来源:https://stackoverflow.com/questions/9048334/asp-net-code-behind-show-images-from-db-wrapped-by-lightbox