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

Editting GridHyperLinkColumn NavigateUrl in codebehind

3 Answers 688 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 25 Nov 2011, 02:02 AM
Hi,
I would like to edit a gridhyperlinkcolumn's navigateurl in my code behind. I have tried:
RadGrid grid = (RadGrid)sender;
GridColumn column = grid.Columns.FindByUniqueName("ViewBus");
(column as GridHyperLinkColumn).NavigateUrl = "www.google.ca";


in both the PreRender and DataBound events. Any suggestions?

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Nov 2011, 05:06 AM
Hello,

You can try the following code snippet.
CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {
    if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
     {
      GridDataItem dataItem = (GridDataItem)e.Item;
      //get the Hyperlink using the Column uniqueName
      HyperLink hyperLink = (HyperLink)dataItem["CompanyName"].Controls[0];
      hyperLink.NavigateUrl = "http://www.telerik.com/help/aspnet-ajax/introduction.html";
     }
 }

Thanks,
Princy.
0
Matt
Top achievements
Rank 1
answered on 22 Jun 2016, 07:49 PM
I did this exactly and it still doesn't work. Now, I know it's 2016, maybe something has changed but I wouldn't think that this would have....
0
Eyup
Telerik team
answered on 27 Jun 2016, 10:27 AM
Hello Matt,

Please make sure that the "ColumnName" you are using matches the UniqueName of the GridHyperLinkColumn - it is case-sensitive. Also, you can check the attached web site sample and try accessing the generated HyperLink there.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Jim
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Matt
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or