How do I properly show a link in a GridViewHyperlinkColumn

5 posts, 1 answers
  1. Pavel
    Pavel avatar
    32 posts
    Member since:
    Sep 2016

    Posted 27 Jan 2017 Link to this post

    I want to be able to show a link, but have the display text be something different.

    This is what I want to see <a href="http://www.googe.com">Google</html>

    What's the correct way to do that? Preferably without having to override some on row creating event.

  2. Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 30 Jan 2017 Link to this post

    Hi Pavel,

    To show HTML links you can use the HTML-like text formatting with a regular textbox column. Please note that each value must start with the "<html>" tag. In addition, you need to set the DisableHTMLRendering property to false:
    private void RadGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.Column.Name == "Name")
        {
           e.CellElement.DisableHTMLRendering = false;
        }
        else
        {
            e.CellElement.DisableHTMLRendering = true;
        }
        
    }

    I hope this information is useful. Let me know if you need further assistance.

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Pavel
    Pavel avatar
    32 posts
    Member since:
    Sep 2016

    Posted 30 Jan 2017 in reply to Dimitar Link to this post

    What about actually setting the HTML text?

    Do I need to create a custom field in my data source that will contain HTML?

    Or is there a way to say something like this $"<a href='{LinkUrl}">{LinkTitle}</html>"

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 31 Jan 2017 Link to this post

    Hi Pavel, 

    You can set the string in the CellFormatting event as well:
    private void RadGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.Column.Name == "Name")
        {
            string LinkUrl = "www.google.com";
            string LinkTitle = "GOOGLE";
     
            e.CellElement.Text = $"<html> <a href=\"{LinkUrl}\" >{ LinkTitle}";
            e.CellElement.DisableHTMLRendering = false;
        }
           
     
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Pavel
    Pavel avatar
    32 posts
    Member since:
    Sep 2016

    Posted 31 Jan 2017 in reply to Dimitar Link to this post

    So, that's not quite as clean as I wanted, so I just added a property to Model class called UrlHtml that returns the properly formatted strring.
Back to Top