Hyperlink in GridView as part of the data set


I am using the following code to populate a GridView with a dataset. Instead of outting text in the column "Title", I want to put a hyperlink to a certain URL. How would I convert the line
        dr("Title") = "Winter"
to a hyperlink that links to ""

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Function GetData() As DataTable
        ' This method creates a DataTable with four rows.  Each row has the
        ' following schema:
        '   PictureID      int
        '   PictureURL     string
        '   Title          string
        '   DateAdded      datetime
        Dim dt As New DataTable()
        ' define the table's schema
        dt.Columns.Add(New DataColumn("PictureID", GetType(Integer)))
        dt.Columns.Add(New DataColumn("PictureURL", GetType(String)))
        dt.Columns.Add(New DataColumn("Title", GetType(String)))
        dt.Columns.Add(New DataColumn("DateAdded", GetType(DateTime)))
        ' Create the four records
        Dim dr As DataRow = dt.NewRow()
        dr("PictureID") = 1
        dr("PictureURL") = ResolveUrl("~/Resources/Craighall_Hands_On_Retreat.jpg")
        dr("Title") = "zBlue Hills"
        dr("DateAdded") = New DateTime(2005, 1, 15)
        dr = dt.NewRow()
        dr("PictureID") = 2
        dr("PictureURL") = ResolveUrl("~/Resources/Craighall_Park_Abbey_Guest_House.jpg")
        dr("Title") = "Sunset"
        dr("DateAdded") = New DateTime(2005, 1, 21)
        dr = dt.NewRow()
        dr("PictureID") = 3
        dr("PictureURL") = _
        dr("Title") = "Water Lilies"
        dr("DateAdded") = New DateTime(2005, 2, 1)
        dr = dt.NewRow()
        dr("PictureID") = 4
        dr("PictureURL") = ResolveUrl("~/Resources/Melrose_The_Peech_Hotel.jpg")
        dr("Title") = "Winter"
        dr("DateAdded") = New DateTime(2005, 2, 18)
        Return dt
    End Function
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Paul MacDonaldConnect With a Mentor Director, Information SystemsCommented:
There are lots of ways to do this, depending on some other factors.  The easiest may be to have the title column as a TemplateField and put something like...
                  <a href='<%# EVAL("PictureURL") %>' > <%# EVAL("Title") %> </a>
...which should take the url and inject it into the href property, and take the title and inject it into the text.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.