Can someone provide a working example of how we can compare data in different rows but within the same column? Or see what I'm missing?
Below is a function that throws an error due to an index not existing... but the data populates. If I remove most of the code and add an alert box, it shows the itemindex #.
This grid is populated from code-behind and the columns are dynamic (meaning, specified by the data, not in the markup).
ADMIN EDIT: Solution created by OP: https://www.telerik.com/forums/compare-data-in-different-rows-but-same-column#4BzUDXkNFU2U_FM8atHFbw.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
RadGrid radGrid = (RadGrid)sender;
if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
GridDataItem gridDataItem = (GridDataItem)e.Item;
if (e.Item.ItemIndex > 0)
{
decimal fte;
decimal fteTarget;
GridDataItem previousGridDataItem = radGrid.Items[1];
GridDataItem currentGridDataItem = radGrid.Items[2];
for (int c = 1; c < previousGridDataItem.Cells.Count; c++)
{
if (decimal.TryParse(previousGridDataItem.Cells[c].Text, out fte) && decimal.TryParse(currentGridDataItem.Cells[c].Text, out fteTarget))
{
if (fte <= fteTarget)
{
previousGridDataItem.Cells[c].ForeColor = Utility.Green;
}
else if (fte > fteTarget)
{
previousGridDataItem.Cells[c].ForeColor = Utility.Red;
}
}
}
}
}