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

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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 "";
          }

        }

Method 2

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

Method 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>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x