Editting GridHyperLinkColumn NavigateUrl in codebehind

4 posts, 1 answers
  1. Jim
    Jim avatar
    1 posts
    Member since:
    Sep 2011

    Posted 24 Nov 2011 Link to this post

    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?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Nov 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matt
    Matt avatar
    49 posts
    Member since:
    Jun 2012

    Posted 22 Jun Link to this post

    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....
  5. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 27 Jun Link to this post

    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.
Back to Top