c# - Check if gridview column on each row has the same values -


how can check if grid-view column on each row has same values.

what condition applied on below code.

code

int y = 0; foreach (gridviewrow row in gridreq.rows) {     string catid = row.cells[2].text;     if (//condition)     {         y = y + 1;      } }  if (y == 0) {  //code  } else {  //code } 

other foreach inside foreach, there no feasible way check row's value against all other row's values. workarounds:

maybe check against first value?

int y = 0; var checkitem = gridreq.rows[0].cells[2].text; foreach (gridviewrow row in gridreq.rows) {     string catid = row.cells[2].text;     if (catid == checkitem)    //or use string.compare here     {         y = y + 1;      } } 

another way check value against of row before it.

int y = 0; string catidcheck = ""; foreach (gridviewrow row in gridreq.rows) {     string catid = row.cells[2].text;     if (catid == catidcheck)    //or use string.compare here     {         y = y + 1;     }     catidcheck = catid; } 

Comments

Popular posts from this blog

javascript - How do you prevent nested queries/catches in sequelize? -

java - Could not retrieve pre-bound Hibernate session - Could not obtain transaction-synchronized Session for current thread -

ruby on rails - ActiveRecord order not working -