Hyperlink Column and Expression col FormatString

2 posts, 1 answers
  1. David A.
    David A. avatar
    126 posts
    Member since:
    Aug 2008

    Posted 06 Oct 2013 Link to this post


    I have a few issues and am using version 2012.2.608.20. 

    1) Hyperlink column ignores TextAlignment property for column and I have also set this with cell.ContentElement.TextAligment in the CellFormatting event.  Neither will center the column contents.

    2) My Hyperlink column does not contain a url, but simply is used to launch a detail form (it is a date field).  The HyperlinkOpened/HyperlinkOpening have no effect and do not execute when the Hyperlink column/text is clicked.  Is it possible to use the Hyperlink column for something other than a url?

    3) I have used the Expression property of a textbox column to add the totals of other columns and this works.  However, I have set the FormatString to {0:C2} and it does not work.  The column is unformatted and does not show the $ sign or the comma in the number.  What am I doing wrong?

    Thank you,
    David A.
  2. Answer
    George avatar
    500 posts

    Posted 10 Oct 2013 Link to this post

    Hello David,

    Thank you for writing.

    I can confirm that the TextAlignment property of the GridViewHyperlinkColumn does not work with previous version, however It is working correctly in the latest release - 2013 Q2 724. I would recommend you upgrade to the latest version. You can find the issue in our Public Issue Tracking System on the following url - http://www.telerik.com/support/pits.aspx#/details/Issue=12023.

    With the latest version the HyperlinkOpening event is being fired, but the HyperlinkOpened is not because the hyperlink is not in a valid format. Moreover the hyperlink column is created for links and if you want to achieve any additional functionality, such as opening a new form, you need to implement that functionality yourself. For this you can use the HyperlinkOpening or the CellClick event:
    void grid_CellClick(object sender, GridViewCellEventArgs e)
        if (e.Column is GridViewHyperlinkColumn)
            if ((this.grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "form1"))
                new Form1().Show();

    Format string of this sort would not work if the underlying value of the cell is string. That is why you would need to either use a GridViewDecimalColumn which will format the value out-of-the-box or format the string on the CellFormatting event:
    void grid_CellFormatting(object sender, CellFormattingEventArgs e)
        if (e.CellElement.ColumnInfo is GridViewTextBoxColumn)
            double value;
            if (double.TryParse(e.CellElement.RowInfo.Cells[e.ColumnIndex].Value + " ", out value))
                e.CellElement.Text = string.Format(e.CellElement.FormatString, value);

    I hope this helps.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top