HTML hyperlink in cell to fire C# event

1 Answer 13 Views
GridView
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Carl asked on 19 Apr 2024, 12:39 PM

I need to create a grid that looks like this:

In the upper right there is an X that need to be a hyperlink which fires a C# event. I'm preparing the data for the grid like this:

foreach (var item in data)
{
    item.Name = $"<html><span style=\"font-size: 10\">{item.Name} {item.Acct}</span><p>{item.TicklerDesc}</html>";
    item.TicklerDate = $"<html><p></p><span style=\"font-size: 8\">{string.Concat(Enumerable.Repeat("&nbsp;", 22))}X<p></p>{item.TicklerDate}</span></html>";
}

As it stands now the X is useless. The questions is: How do I make it a hyperlink (or fake equivalent) so that I can fire a C# event?

Thanks

Carl

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 24 Apr 2024, 09:42 AM

Hello, Carl,

To achieve a hyperlink in RadGridView you can use the Html like text formatting and use the "a href" tag to specify the link URL. This can happen in the CellFormatting event:

private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Column.HeaderText == "Hyperlink column" && e.CellElement.Value != null)
    {
        string LinkUrl = "www.telerik.com"; 
        string LinkTitle = "X";
        e.CellElement.Text = $"<html> <a href=\"{LinkUrl}\" >{LinkTitle}";
        e.CellElement.DisableHTMLRendering = false;
    }
}

If you need to fire an event when you click on the link in cell, then you can consider using a GridViewHyperlinkColumn. GridViewHyperlinkColumn offers the following specific events:

  • HyperlinkOpening: cancelable event which is raised before opening the hyperlink;
  • HyperlinkOpened: event which is raised after opening the link.;

I hope this information helps. If you have further questions, please let me know. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Tags
GridView
Asked by
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or