开发者

How to iterative through an table using foreach condition in C#

开发者 https://www.devze.com 2022-12-11 09:16 出处:网络
I have an table. I need to iterate, for each(datarow r in datatable.rows){ foreach(datacolumns c in datatable.columns){

I have an table. I need to iterate,

for each(datarow r in datatable.rows){
  foreach(datacolumns c in datatable.columns){
     if()  // nee开发者_如何学JAVAd  to  write an  condition 
      {
       // apply css
      }
     else
      {
        //no need  to apply css
      }
  }
}

I have an column as Menu_ID if MEnu_ID as an value "7" the dnt apply the css how to write an condition here.


If I understood correctly, you need something like this:

foreach(datarow r in datatable.rows)
{
    if(((int)r["Menu_ID"])==7) {
        //Don't apply CSS
    } else {
        //Apply CSS
    }
}

this is assuming your Menu_ID column is numeric. If it is a string, change to:

if(((string)r["Menu_ID"])=="7")


for(int i=0; i<= datatable.rows.count-1; i++)
{
    if(datatable.Rows[i]["ColName"] == "1")
    {
     //do something
    }
    else
    {
      //do something
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消