Try Now
More in this section

Forums / Developing with Sitefinity / Auto-generated columns format as currency

Auto-generated columns format as currency

2 posts, 0 answered
  1. Jason Green
    Jason Green avatar
    53 posts
    18 Sep 2009
    05 May 2011
    Link to this post
    Pre:  I am posting this here because I am doing this inside a sitefinity user control using the version of the controls that comes with 3.7.

    I have a RadGrid with AutoGenerateColumns=True.  This grid is showing a pivot table from SQL which is working great.  I would like to set all of the dynamic columns to format as decimal or currency, but can't seem to find the correct properties exposed.

    I followed the instructions on http://www.telerik.com/help/aspnet-ajax/grdusingcolumns.html under the "Auto-generated columns" section.  Here is my code:

    protected void radGidDataList_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        if (e.Column.UniqueName == "ID")
            e.Column.Visible = false;
        else if (e.Column.UniqueName == "Name")
            e.Column.HeaderStyle.Width = 200;
            e.Column.ItemStyle.Font.Bold = true;
            GridBoundColumn boundColumn = e.Column as GridBoundColumn;
            boundColumn.DataFormatString = "{0:c}";

    The problem is that boundColumn is always NULL because e.Column is of type "GridExpandColumn" and not "GridBoundColumn".  Changing the code to be:

    GridExpandColumn objColumn = e.Column as GridExpandColumn;

    does not work, because GridExpandColumn does not have a property for DataFormatString.  How do I format the display of data in AutoGeneratedColumns?
  2. Tsvetina
    Tsvetina avatar
    2 posts
    13 Sep 2017
    11 May 2011
    Link to this post
    Hi Jason,

    Your code should work if you put a check on the column type before performing the cast. The thing is that RadGrid fires the ColumnCreated event for the expand column more than once:
    else if (e.Column.ColumnType == "GridBoundColumn")
        //cast to bound column

    Kind regards,
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

2 posts, 0 answered