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

Setting up different urls for different rows for a hyperlink column

7 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ash
Top achievements
Rank 1
Ash asked on 05 May 2008, 03:01 PM
I have a Radgrid Control on my aspx page with one hyperlink column I bind my grid with my datatable.  But the hyperlink column data will point to different urls, depends on its value. I need to check  the values on every rowbound and then setup the url for that row. How do I do that.

7 Answers, 1 is accepted

Sort by
0
Prangadj
Top achievements
Rank 1
answered on 05 May 2008, 03:22 PM
Try to set the DataNavigateUrlFormatString for the hyperlink column as in this example:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/GeneralFeatures/ColumnTypes/DefaultCS.aspx

Other thing is to attach the ItemDataBound event of the grid and change the url for the generated link in the cell. The link should be the first control in the Controls collection of the cell (I understood it from here).

Prangadj
0
anna
Top achievements
Rank 1
answered on 05 May 2008, 05:15 PM
your answer is not clear. how do I do this programatically in code behind, setting up different urls for each row.  what event fires for each rowbound.
0
Shinu
Top achievements
Rank 2
answered on 06 May 2008, 07:50 AM
Hi,

Try the following code snippet to achieve the desired scenario.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            HyperLink hyplnk = (HyperLink)item["columnUniqueName"].Controls[0]; 
            string strVal = item["ProductName"].Text.ToString(); 
            if (strVal == "Chai") 
            { 
                hyplnk.NavigateUrl = "~/Default1.aspx"
            } 
            else if (strVal == "Coffee") 
            { 
                hyplnk.NavigateUrl = "~/Default2.aspx"
            } 
            else 
            { 
                hyplnk.NavigateUrl = "~/Default3.aspx"
            } 
             
        } 
   } 


Thanks
Shinu.
0
Ash
Top achievements
Rank 1
answered on 06 May 2008, 03:30 PM
ok, Thank you so much.
0
Ash
Top achievements
Rank 1
answered on 06 May 2008, 04:54 PM
I get this error:

Specified argument was out of the range of valid values.
Parameter name: index
 

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)

If TypeOf e.Item Is GridDataItem Then

Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)

Dim hyplnk As HyperLink = DirectCast(item("Desc").Controls(0), HyperLink)

Dim strVal As String = "ups"

If strVal = "ups" Then

hyplnk.NavigateUrl =

"www.google.com"

ElseIf strVal = "yahoo" Then

hyplnk.NavigateUrl =

"www.yahoo.com"

Else

hyplnk.NavigateUrl =

"Default.aspx"

End If

End If

End Sub

my grid:

<

telerik:RadGrid ID="RadGrid1" OnItemDataBound="RadGrid1_ItemDataBound" runat="server">

</telerik:RadGrid>


I am binding my grid with a datatable:

num(0) =

"1"

 

num(1) =

"2"

 

sport(0) =

"rr"

 

sport(1) =

"socc"

 

 

Dim dt As New Data.DataTable

Dim dr As Data.DataRow

' Dim hl As New HyperLink

 

Dim i As Integer

 

dt.Columns.Add(

New Data.DataColumn("Desc", GetType(String)))

dt.Columns.Add(

New Data.DataColumn("Desc2", GetType(String)))

' dt.Columns.Add(New Data.DataColumn("Category", GetType(String)))

 

For i = 0 To 1

dr = dt.NewRow

dr(

"Desc") = num(i) 'The link's

 

dr(

"Desc2") = sport(i)

 

' dr("Category") = cat(0) 'The link's category

 

dt.Rows.Add(dr)

Next

 

Dim ds2 As New DataSet()

ds2 =

New DataSet()

''creating a dataset

 

ds2.Tables.Add(dt)

RadGrid1.DataSource = dt

RadGrid1.DataBind()

0
Princy
Top achievements
Rank 2
answered on 07 May 2008, 06:17 AM
Hi,

Try Binding the Grid using AdvanceDataBinding technique.
Advanced data-binding

Thanks
Princy.
0
ervin
Top achievements
Rank 1
answered on 23 Jun 2011, 06:51 PM
Thanks...
Tags
Grid
Asked by
Ash
Top achievements
Rank 1
Answers by
Prangadj
Top achievements
Rank 1
anna
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Ash
Top achievements
Rank 1
Princy
Top achievements
Rank 2
ervin
Top achievements
Rank 1
Share this question
or