RadGridView Hyperlink Column (Text and Hyperlink in cell) Opening Link twice.

1 Answer 52 Views
GridView
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 14 Sep 2021, 06:09 PM

I have a databound radgridview. 

 

I have added a GridViewHyperLinkColumn as seen below to the grid after the databound.

GridViewHyperlinkColumn col = new GridViewHyperlinkColumn();

                    col.Width = 200;
                    col.FieldName = "Title";
                    col.HeaderText = "Title";
                    col.Name = "Title";
                    col.HyperlinkOpenAction = HyperlinkOpenAction.SingleClick;
                    gvResults.Columns.Insert(5, col);

 

On the CellFormatting I have added the follow to show a short text but a different Hyperlink

 private void gvResults_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
        {
            if(e.Column.Name == "Title")
            {
                string LinkUrl = e.Row.Cells["Path"].Value.ToString();
                string LinkTitle = e.CellElement.Text;
                e.CellElement.Text = $"<html> <a href=\"{LinkUrl}\" >{ LinkTitle}";
                e.CellElement.DisableHTMLRendering = false;
                e.CellElement.ToolTipText = LinkUrl;
            }
        }

 

I have registered

gvResults.HyperlinkOpening += gvResults_HyperlinkOpening;

 

And perform some items during this that include Opening the link using the ProcessStart.

 

My issue is the link opens in a browser before the gvResults_Hyperlink event is called.

I DO NOT want the LINK to open automatically, I want the gvResults_HyperLinkOpening event to do the open.

 

Any suggestions?

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Sep 2021, 01:51 PM
Hello, Roger, 

To be honest, the code you have in the CellFormatting event is appropriate for GridViewTextBoxColumn, not GridViewHyperlinkColumn.

When using a GridViewHyperlinkColumn, the HyperlinkOpening event is fired when the user clicks a cell from this column. You control whether to open a certain link with the help of Process.Start method. However, in case you are customizing the cell's text in the CellFormatting event and you are using HTML-like text formatting to simulate hyperlinks, note that the text will be displayed as a hyperlink and clicking the underlined text will open automatically the link regardless of the code available in the HyperlinkOpening event. That is why the link may be opened twice. 

It is recommend to use either a GridViewTextBoxColumn with the code inside the CellFormatting event or use a HyperlinkOpening event and open the link in the HyperlinkOpening event. Feel free to use this approach which suits your requirements best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 15 Sep 2021, 03:29 PM

Thanks for the differentiation.   I was confused and now understand why I am getting the double opening.

 

Roger

Tags
GridView
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or