Setting up different urls for different rows for a hyperlink column

8 posts, 0 answers
  1. Ash
    Ash avatar
    8 posts
    Member since:
    May 2008

    Posted 05 May 2008 Link to this post

    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.
  2. Prangadj
    Prangadj avatar
    174 posts
    Member since:
    Jan 2008

    Posted 05 May 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. anna
    anna avatar
    17 posts
    Member since:
    Apr 2008

    Posted 05 May 2008 Link to this post

    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.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 May 2008 Link to this post

    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.
  6. Ash
    Ash avatar
    8 posts
    Member since:
    May 2008

    Posted 06 May 2008 Link to this post

    ok, Thank you so much.
  7. Ash
    Ash avatar
    8 posts
    Member since:
    May 2008

    Posted 06 May 2008 Link to this post

    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()

  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2008 Link to this post

    Hi,

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

    Thanks
    Princy.
  9. ervin
    ervin avatar
    22 posts
    Member since:
    May 2011

    Posted 23 Jun 2011 Link to this post

    Thanks...
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017