tags:

views:

77

answers:

3

Hi

I want to compare rows of two grid views.GW1 and GW2.

When I click a Search Button ,I want to check the Values in the GW2,and if GW1 and GW2 have same PayID ,EmpID,then that specific row of GW1 must be disabled

Thanks

A: 

Only way I can think of is to loop through table one and search for similar rows in table two. This is how you can do this:

  1. Loop through the Table 1.
  2. Use DataTable.Select to find if there are rows with same PayID and EmpID in Table 2.
  3. If the method returns more than 0 rows, then disable the rows.

Apart from this, you can also think about writing/searching a method which can give you intersection of two tables. If these two columns are priamry keys, then this will work. If not, then you will need to tweak the code as per your need.

danish
A: 

do something like this, its not the actual code, but you will have the idea.

for i=0 to gw1rowscount-1 for j=0 to gw2rowscount-1

   if gw1(i)(column1)=gw2(j)(column1) and gw1(i)(column2)=gw2(j)(column2) then

   end if

 next

next

Ali
+1  A: 
int i = 0;

while(i < GridView1.Rows.Count && i < GridView2.Rows.Count)
{

if(
GridView1.Rows[i].Cells[column for pay ID].Text == GridView2.Rows[i].Cells[column for pay ID].Text && 
GridView1.Rows[i].Cells[column for emp ID].Text == GridView2.Rows[i].Cells[column for emp ID].Text))
{
GridView1.Rows[i].Enabled = false;
}


i++;

}
sujata