Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6741895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:46:45+00:00 2026-05-26T11:46:45+00:00

Lets say I have a data table with the columns ImageUrl, Text, LinkUrl and

  • 0

Lets say I have a data table with the columns ImageUrl, Text, LinkUrl and Title.

I databind this to a repeater and displays everything without any issue. However, LinkUrl can be empty and then I want the code to be like the one below. If the LinkUrl contains a string/link then I want to wrap the image with a link to the URL. Please ask questions if I need to clarify more.

Example code:

<asp:Repeater runat="server" ID="rptImageGallery">
<ItemTemplate>
<div class="slide">
    <asp:Image ID="Image1" runat="server" ImageUrl='<%#UrlHelper(DataBinder.Eval(Container.DataItem, "ImageUrl"))%>'>
    <h2><%# DataBinder.Eval(Container.DataItem, "Title") %></h2>
    <p><%# DataBinder.Eval(Container.DataItem, "Text")%></p>
</div>
</ItemTemplate>
</asp:Repeater>

Code behind:

DataTable dt = new DataTable();
dt = collListItems.GetDataTable().AsEnumerable()
    .Where(a => Convert.ToString(a["Published"]) == "1")
        .CopyToDataTable();

rptImageGallery.DataSource = dt;
rptImageGallery.DataBind();

So if the current row contains a link in LikUrl then I want the repeater to present something like this

<asp:Repeater runat="server" ID="rptImageGallery">
<ItemTemplate>
<div class="slide">
    <asp:Image ID="Image1" runat="server" ImageUrl='<%# UrlHelper(DataBinder.Eval(Container.DataItem, "FileLeafRef"))%>' />
    <a href='<%# DataBinder.Eval(Container.DataItem, "LinkUrl")%>' runat="server"><%# DataBinder.Eval(Container.DataItem, "Title") %></h2></a>
    <p><%# DataBinder.Eval(Container.DataItem, "Text")%></p>                       
</div>
</ItemTemplate>
</asp:Repeater>

Any suggestions on how to achieve this?

Edit: something weird with the post. When I go Edit I can see the correct code – slick Save and it doesn’t update my code example. Anyway, in the last code part I want a link wrapping the image or image text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:46:45+00:00Added an answer on May 26, 2026 at 11:46 am

    try this:

    <asp:Repeater ID="rpt1" runat="server">
        <ItemTemplate>
            <div class="slide">
                <asp:Image ID="img1" runat="server" ImageUrl='<%#GetUrl(Eval("Image"))%>'/>
                <%# WrapTitle(Eval("Title"), Eval("Link"))%>
            </div>
        </ItemTemplate>
    </asp:Repeater>
    

    code behind (I have added complete code so that you can test):

    Public Class Repeater
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Dim dt As DataTable = New DataItem().GetData()
                rpt1.DataSource = dt
                rpt1.DataBind()
            End If
        End Sub
    
        Protected Function WrapTitle(ByVal title As Object, ByVal lnk As Object) As String
            If Not String.IsNullOrWhiteSpace(lnk.ToString()) Then
                Return String.Format("<a href='{0}'>{1}</a>", lnk, title)
            End If
            Return title.ToString()
        End Function
    
        Protected Function GetUrl(ByVal img As String) As String
    
            Return Page.ResolveUrl("~/Images/") + img
        End Function
    
    End Class
    
    Public Class DataItem
        Private lnks() As String = {"http://www.google.com", "http://www.yahoo.com", "http://www.bing.com", "http://www.superuser.com", "http://www.stackoverflow.com", ""}
        Private titles() As String = {"Google", "Yahoo", "Bing", "superuser", "stackoverflow", "ask.com"}
        Private images() As String = {"nav_logo91.png", "yahoo.png", "bing.png", "superuser.png", "stackoverflow.png", ""}
    
        Public Function GetData() As DataTable
            Dim dtb As New DataTable
            dtb.Columns.Add("title")
            dtb.Columns.Add("link")
            dtb.Columns.Add("Image")
    
            For i As Integer = 0 To titles.Length - 1
                dtb.Rows.Add(New Object() {titles(i), lnks(i), images(i)})
            Next
    
            Return dtb
        End Function
    
    End Class
    

    PS:- probably you will not need GetUrl function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have 2 columns in my data Grid: Column A: Selected, and
For examples sake, lets say I have a table containing these columns ID (primary
I have two tables. Lets say they look like this Table Sports: Column 1:
Lets say I have a really big table filled with lots of data (say,
Hoping someone can help me out with this. Lets say I have a table
Let's say I have a table tbl with columns id and title . I
Lets say we have a following table with two columns and following rows of
Lets say I have data in two tables. In one I have Order ID
Let's say I have a table containing following data: | id | t0 |
Kinda stuck here... I have an application with lets say 5000 rows of data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.