Display images in a Repeater (vb.net)

dennis_hs
dennis_hs used Ask the Experts™
on
Hello.

I'm trying to display images in a Repeater. I've searched EE and Google, but didn't really find anything suitable. Maybe because I want to avoid any code behind programming (only in this case though).

I have a field in the SQL db for the image path (varschar). Should I keep the entire path and image name? Or just the image name and then hardcode the folder path in the asp code?

Anyway, how do I display images the best way? If I have to do any programming to make it work, that's ok...

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
http://articles.sitepoint.com/article/asp-net-repeater-control

this article may be helpful.. U'll have to do a little bit of coding which is shown in this article
Commented:
Following code may also be help ful
<asp:Repeater id="myRepeaterPlain" runat="server">
  <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "Id") %>,
    <%# DataBinder.Eval(Container.DataItem, "Name") %>,
    <%# DataBinder.Eval(Container.DataItem, "URL") %>,
    <%# DataBinder.Eval(Container.DataItem, "Image") %>
    <br />
  </ItemTemplate>
</asp:Repeater>

<hr />

<asp:Repeater id="myRepeaterUL" runat="server">
  <HeaderTemplate>
    <ul>
  </HeaderTemplate>
  <ItemTemplate>
    <li><a href="<%# DataBinder.Eval(Container.DataItem, "URL") %>">
      <%# DataBinder.Eval(Container.DataItem, "Name") %></a></li>
  </ItemTemplate>
  <FooterTemplate>
    </ul>
  </FooterTemplate>
</asp:Repeater>

<hr />

<asp:Repeater id="myRepeaterAltSep" runat="server">
  <HeaderTemplate>
    <p><strong>Selected ASP Sites:</strong><br />
  </HeaderTemplate>
  <ItemTemplate>
    <a href="<%# DataBinder.Eval(Container.DataItem, "URL") %>">
      <%# DataBinder.Eval(Container.DataItem, "Name") %></a><br />
  </ItemTemplate>
  <AlternatingItemTemplate>
    <font style="background-color: #CCCCFF">
    <a href="<%# DataBinder.Eval(Container.DataItem, "URL") %>">
      <%# DataBinder.Eval(Container.DataItem, "Name") %></a><br />
    </font>
  </AlternatingItemTemplate>
  <SeparatorTemplate>
    -----------------------<br />
  </SeparatorTemplate>
  <FooterTemplate>
    <strong>End Selected ASP Sites</strong></p>
  </FooterTemplate>
</asp:Repeater>

<hr />

<asp:Repeater id="myRepeaterImage" runat="server">
  <ItemTemplate>
    <a href="<%# DataBinder.Eval(Container.DataItem, "URL") %>">
      <img src="<%# DataBinder.Eval(Container.DataItem, "Image") %>"
      border="0"
      alt="<%# DataBinder.Eval(Container.DataItem, "Name") %>"/></a>
  </ItemTemplate>
</asp:Repeater>

Open in new window

Carl TawnSenior Systems and Integration Developer
Commented:
You can do it purely through markup, as long as the object you are binding to exposes a property with your image path:

        <asp:Repeater ID="ImageRepeater" runat="server">
            <ItemTemplate>
                <asp:Image ID="TheImage" runat="server" ImageUrl='<%# Eval("ImagePath") %>' />
            </ItemTemplate>
        </asp:Repeater>

Open in new window

Author

Commented:
Thanks..

I went for:

The filename of the image in the SQL db and just added:

" />

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial