This is a migrated thread and some comments may be shown as answers.

Problem with numeric column formating

2 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 02 Jan 2011, 08:38 PM

I have a numeric column in a grid that receives numbers from a datatable. The cell is conditionally formatted during OnItemDataBound to change color depending on the how larger the number in the cell is.

I would like to format the number in the column regardless of how larger it is so that it displays , thousands separator. However, when I use a DataFormatString (either in code or via a PreRender method) an exception is thrown because the number no long matches (1000 vs 1,000).

 

How can I properly format the data in the column while allowing it to be conditionally formated?

2 Answers, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 2
answered on 02 Jan 2011, 09:02 PM
Here is the conditional formatting code, Ive tried this both with and without the NumberStyles.AllowThousands:

protected void grd_display_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataBoundItem = e.Item as GridDataItem;
        if (int.Parse(dataBoundItem["packets"].Text.ToString(), NumberStyles.AllowThousands) > 1000000)
        {
            dataBoundItem["packets"].BackColor = Color.Goldenrod;
            dataBoundItem["dest_ip"].BackColor = Color.Goldenrod;
            dataBoundItem["device"].BackColor = Color.Goldenrod;
            dataBoundItem["ISP"].BackColor = Color.Goldenrod;
            dataBoundItem["packets"].Font.Bold = true;
            dataBoundItem["dest_ip"].Font.Bold = true;
            dataBoundItem["device"].Font.Bold = true;
            dataBoundItem["ISP"].Font.Bold = true;
              
              
        }
        if (int.Parse(dataBoundItem["packets"].Text.ToString(), NumberStyles.AllowThousands) > 10000000)
        {
            dataBoundItem["packets"].BackColor = Color.Firebrick;
            dataBoundItem["dest_ip"].BackColor = Color.Firebrick;
            dataBoundItem["device"].BackColor = Color.Firebrick;
            dataBoundItem["ISP"].BackColor = Color.Firebrick;
        }
    }
}
0
Radoslav
Telerik team
answered on 06 Jan 2011, 01:04 PM
Hi Joe,

I tried to reproduce the described issue, but to no avail. I am sending you a simple example. Please check it out and let me know what differs in your case.
Looking forward for your reply.

Kind regards,
Radoslav
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.
Tags
Grid
Asked by
Joe
Top achievements
Rank 2
Answers by
Joe
Top achievements
Rank 2
Radoslav
Telerik team
Share this question
or