asp.net code behind show images from DB wrapped by lightbox

梦想的初衷 提交于 2019-12-08 12:39:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!