如何写“for-loop”检查C#.net中的条件 [英] How to write "for-loop" to check condition in C#.net

查看:75
本文介绍了如何写“for-loop”检查C#.net中的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据集中有一些数据。我想检查具有特定条件的数据,如果条件为真,那么文本框应该是可见的,否则文本框不应该是可见的。在数据集中我有20条记录。



条件如下:

I have some data in data set.I want to check the data with a specific condition,if the condition is true then a text box should be visible otherwise text box should n't be visible.In dataset I have 20 records.

the condition is like:

if ((dataset.Tables[0].Rows[i][0].ToString())=="FirstName"&&(dataset.Tables[0].Rows[i][3].ToString())=="block")
                     
{
     divFirstName.Visible = true;
     txtFName.Text = objUser.FirstName;
}



注意:

这里firstname和block是列中的值。

如果特定行符合条件,那么我们必须显示文本框。

我们需要搜索数据集行集合中的值。



如何为此要求编写循环?



先谢谢


Note:
Here "firstname" and "block" are the values in columns.
if a particular row meets the condition,then we have to show text box.
we need to search that values in data set rows collection.

How to write for loop for this requirement?

Thanks in Advance

推荐答案

你可以在这里使用foreach循环,如下所示:

You can use foreach loop here as follows,
foreach(DataRow objRow in dataset.Tables[0].Rows)
{
   if(objRow[0].ToString().Trim() == "FirstName" &&
      objRow[3].ToString().Trim() == "block")
   {
      divFirstName.Visible = true;
      txtFName.Text = objUser.FirstName;
   }
}


这篇关于如何写“for-loop”检查C#.net中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆