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

formating highest number

4 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 13 Sep 2012, 11:10 PM
Can someone tell me how I can find the highest number in each column and format it to make it stick out?

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 18 Sep 2012, 11:11 AM
Hi Michael,

Could you please try the following approach?
int index = -1;
decimal maxNumber = decimal.MinValue;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        decimal currentNumber = decimal.Parse(dataItem["Freight"].Text);
        if (currentNumber > maxNumber)
        {
            maxNumber = currentNumber;
            index = dataItem.ItemIndex;
        }
    }
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (index >= 0)
    {
        GridTableCell cell = (RadGrid1.Items[index] as GridDataItem)["Freight"] as GridTableCell;
        cell.BackColor = System.Drawing.Color.LightBlue;
    }
}

That should do the trick. Please give it a try and let me know about the result.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Michael
Top achievements
Rank 1
answered on 18 Sep 2012, 11:51 AM
This works for one row but doesn't do it for each column.
0
Accepted
Eyup
Telerik team
answered on 20 Sep 2012, 12:42 PM
Hi Michael,

In this case you could use the approach shown below:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    string[] numericColumns = { "OrderID", "Freight", "Freight1", "Freight2" };
    foreach (string uniqueName in numericColumns)
    {
        int index = -1;
        decimal maxNumber = decimal.MinValue;
        foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
        {
            decimal currentNumber = decimal.Parse(dataItem[uniqueName].Text);
            if (currentNumber > maxNumber)
            {
                maxNumber = currentNumber;
                index = dataItem.ItemIndex;
            }
        }
        if (index >= 0)
        {
            GridTableCell cell = (RadGrid1.Items[index] as GridDataItem)[uniqueName] as GridTableCell;
            cell.BackColor = System.Drawing.Color.LightBlue;
        }
    }
}

I hope this will prove helpful.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Michael
Top achievements
Rank 1
answered on 22 Sep 2012, 08:43 PM
Thanks Eyup.  That worked great.  Exactly what I was looking for.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Michael
Top achievements
Rank 1
Share this question
or