This is a migrated thread and some comments may be shown as answers.

URL in a Grid

3 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd
Top achievements
Rank 1
Iron
Todd asked on 13 Apr 2011, 06:11 PM
I have a bound grid autogenerating the columns.  One column as an abbreviation in it and another has a URL..  What I'd like to do is have the URL column just be a hyperlink for the abbreviation.  So, how can I make the abbreviation column a hyperlink column then how can i set the URL to be the value of the other column?

3 Answers, 1 is accepted

Sort by
0
Dean
Top achievements
Rank 2
answered on 13 Apr 2011, 07:44 PM
Hi Todd,

I've given you an example below on how you can accomplish your task, the only thing is that I am setting the columns and not autogenerating the columns.

ASP Markup

<telerik:RadGrid ID="grdWebLinks" runat="server" AutoGenerateColumns="False" CellSpacing="0"
    GridLines="None">
    <MasterTableView>
        <Columns>
            <telerik:GridHyperLinkColumn DataNavigateUrlFields="URL" DataTextField="Abbreviation"
                HeaderText="Abbreviation" UniqueName="colAbbrev">
            </telerik:GridHyperLinkColumn>
            <telerik:GridBoundColumn DataField="URL" HeaderText="URL" UniqueName="colURL">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Code Behind
Public Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        grdWebLinks.DataSource = BuildDataSource()
        grdWebLinks.DataBind()
    End Sub
 
    Private Function BuildDataSource() As List(Of MyWebLink)
        Dim oLinks As New List(Of MyWebLink)
        oLinks.Add(New MyWebLink("SA", "http://www.southafrica.net"))
        oLinks.Add(New MyWebLink("CT-SA", "http://www.cape-town.info/"))
        oLinks.Add(New MyWebLink("JB-ZA", "http://www.joburgtourism.com/"))
        Return oLinks
    End Function
End Class
 
Public Class MyWebLink
    Public Property Abbreviation As String
    Public Property URL As String
 
    Public Sub New(ByVal sAbbreviation As String, ByVal sURL As String)
        Abbreviation = sAbbreviation
        URL = sURL
    End Sub
End Class

Hope this helps!
0
Todd
Top achievements
Rank 1
Iron
answered on 13 Apr 2011, 07:47 PM
Ok, but how can I do that with a autogenerated column?
0
Accepted
Dean
Top achievements
Rank 2
answered on 13 Apr 2011, 08:17 PM
Hi Todd,

Automatically-generated columns are aware of the data type of the field/property, You can take a look at the following threads and see if it helps you.

Changing the column type to hyperlink when using AutoGenerateColumns

Dynamic Link buttons created using ItemCreated not firing ItemCommand

Hope you come right.
Tags
Grid
Asked by
Todd
Top achievements
Rank 1
Iron
Answers by
Dean
Top achievements
Rank 2
Todd
Top achievements
Rank 1
Iron
Share this question
or