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

Setting DataNavigateUrlFormatString parameter dynamically

2 Answers 421 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mkasuboski
Top achievements
Rank 1
mkasuboski asked on 08 Apr 2009, 09:01 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Apr 2009, 06:20 AM
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.
0
mkasuboski
Top achievements
Rank 1
answered on 09 Apr 2009, 01:14 PM
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!
Tags
Grid
Asked by
mkasuboski
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mkasuboski
Top achievements
Rank 1
Share this question
or