Rajkumar R

Rajkumar R

  • NA
  • 26
  • 3.6k

Compare Gridviews

Sep 14 2017 4:39 AM
HI,
 
I have 2 gridviews with same columns, but there is a difference in data. Would like to compare 2 gridivews and show the difference data in another gridview or highlight the row
 
can you please suggest
 
the below code is highlighting the entire columns for all rows, it should highlight only specific cells which has the difference in data 
 
private void Compare(GridView g1, GridView g2)
{
foreach (GridViewRow row1 in g1.Rows)
{
if (row1.RowType == DataControlRowType.DataRow)
{
string gv1Value = row1.Cells[2].Text;
//iterate second gridview
foreach (GridViewRow row2 in g2.Rows)
{
if (row2.RowType == DataControlRowType.DataRow)
{
string gv2Value = row2.Cells[2].Text;
string gv4Valuke = row2.Cells[1].Text;
//do comparison here
if (gv1Value.Contains(gv2Value))
{
g1.Rows[row1.RowIndex].Cells[2].BackColor = System.Drawing.Color.Blue;
}
}
}
}
}
 

Answers (3)