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

Get data from non selected row

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 05 Mar 2012, 04:43 PM
I would like to compare each row in a radgrid with the one above it to highlight changes. None of the rows will be selected so i need to somehow get the data for each row and compare it after binding. Is there a way for me to access all of the data in the grid if a row isn't selected?

1 Answer, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 05 Mar 2012, 05:05 PM
Hi Michael,

I believe you could achieve this in the ItemDataBound event of the RadGrid. Something like the below should work.

I hope this helps!
Casey

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
      GridDataItem currItm = e.Item as GridDataItem;
      if (currItm.ItemIndex > 0)
      {
         GridDataItem prevItm = RadGrid1.MasterTableView.Items[currItm.ItemIndex - 1] as GridDataItem;
            //Use the UniqueName for the column you want to compare below
         if (currItm["Column1UniqueName"].Text != prevItm["Column1UniqueName"].Text)
         {
            currItm.BackColor = System.Drawing.Color.Red;
         }
      }
   }
}
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Share this question
or