how to show image in the column of repeater control in asp.net?

拜拜、爱过 提交于 2019-12-31 03:05:16

问题


I'm using repeater control from asp.net for data binding. And for designing i used the div & span for data representation. I have 4 fields to my table & i want to show the images on the each span depending on the field value. Images are stored in my project path itself.

How to do this?


回答1:


Use this

<asp:Repeater ID="RepeaterImages" runat="server">
    <ItemTemplate>
        <img src='<%#GetImage(Databinder.Eval(Container.DataItem, "ImageID"))%>' alt="" width="" height="" />
    </ItemTemplate>
</asp:Repeater>

Now we need to create a function to retrieve the image using that ID.

public string GetImage(object ImadeID)
        {
          if(ImageID!=null)
            {
               //do something with the ImageID to return the image path as string
            }
          else
           {
           return "";
          }

        }



回答2:


<asp:Repeater ID="RepeaterImages" runat="server">
    <ItemTemplate>
        <asp:Image ID="Image" runat="server" ImageUrl='<%# Container.DataItem %>' />
    </ItemTemplate>
</asp:Repeater>



回答3:


<asp:Repeater ID="RepeaterImages" runat="server">
    <ItemTemplate>
        <asp:Image ID="Image" runat="server" ImageUrl='<%# Container.DataItem %>' 
Visible ='<%# Container.DataItem.ToString() == "0" ? true : false %>' />
    </ItemTemplate>
</asp:Repeater>


来源:https://stackoverflow.com/questions/7885444/how-to-show-image-in-the-column-of-repeater-control-in-asp-net

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