Setting DataNavigateUrlFormatString parameter dynamically

3 posts, 1 answers
  1. mkasuboski
    mkasuboski avatar
    17 posts
    Member since:
    Jul 2008

    Posted 08 Apr 2009 Link to this post

    Here is the code snippet from the grid.
                            <telerik:GridHyperLinkColumn DataTextField="EstimateID" UniqueName="EstimateID" HeaderText="Quote #" AllowFiltering="false"  
                                    DataNavigateUrlFormatString="~/QuoteDetail.aspx?EstimateID={0}" DataNavigateUrlFields="EstimateID" SortExpression="EstimateID" 
                                    SortAscImageUrl="~/Images/SortAsc.gif" SortDescImageUrl="~/Images/SortDesc.gif" ItemStyle-Font-Underline="true"
                                <ItemStyle HorizontalAlign="Center" Font-Size="12px" /> 
                            </telerik:GridHyperLinkColumn> 

    I would like to set the DataNavigateUrlFormatString from a field in the bound datatable, just like the visible text field is set by setting the DataTextField property, or set this property in the code behind before the grid is rendered.

    Can this be done and how do I do it??

    Thanks!


  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Apr 2009 Link to this post

    Hello,

    You can access the HyperLink control of the HyperLinkColumn and set its NavigateUrl as shown below:
     protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
          if (e.Item is GridDataItem) 
                { 
                    GridDataItem dataItem = (GridDataItem)e.Item; 
                    foreach (GridColumn col in RadGrid1.Columns) 
                    {                                   
                            string strtxt = dataItem["ProductID"].Text; 
                           ((HyperLink)dataItem["HyperLinkColumn"].Controls[0]).NavigateUrl=String.Format("Default3.aspx?ID={0}", strtxt);                  
                    } 
                 } 
         } 

    Thanks
    Princy.
  3. mkasuboski
    mkasuboski avatar
    17 posts
    Member since:
    Jul 2008

    Posted 09 Apr 2009 Link to this post

    Princy,
    Thanks for the response.  You pushed in the right direction to resolve my questions.

    Here is how I did it.

        Protected Sub rgEstimates_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgEstimates.ItemDataBound 
                If Me._NotAuthenticated Then 
                    Exit Sub 
                End If 
                If e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem Then 
                    Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) 
                    Dim currentRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView) 
                    For Each col As GridColumn In rgEstimates.Columns 
                        If col.UniqueName = "EstimateID" Then 
                            Dim strTxt As String = currentRow.Row("currOrderLink").ToString 
                            CType(dataItem("EstimateID").Controls(0), HyperLink).NavigateUrl = String.Format("JavaScript:openEstimateDetail('{0}');", strTxt) 
                        End If 
                    Next 
                End If 
            End Try 
        End Sub 

    Thanks again for your help!
Back to Top