当前位置: 代码迷 >> ASP.NET >> 怎么判断gridview里某一行的值是否在datatable中
  详细解决方案

怎么判断gridview里某一行的值是否在datatable中

热度:9373   发布时间:2013-02-25 00:00:00.0
如何判断gridview里某一行的值是否在datatable中
string ConnString = "";
  SqlConnection srcConnection = new SqlConnection();
  SqlCommand sqloldbranch = new SqlCommand();
  SqlDataAdapter daoldbranch = new SqlDataAdapter();
  DataTable dtoldbranch = new DataTable();
  ConnString = ConfigurationManager.ConnectionStrings["connstr"].ToString();
  srcConnection.ConnectionString = ConnString;
  sqloldbranch.Connection = srcConnection;
  sqloldbranch.CommandText = "select 商场代码,商场名称 from test";
  sqloldbranch.CommandType = CommandType.Text;
  sqloldbranch.Connection.Open();
  daoldbranch.SelectCommand = sqloldbranch;
  daoldbranch.Fill(dtoldbranch);
  sqloldbranch.Connection.Close();

  // for (int j = 0; j < dtoldbranch.Rows.Count; j++)
  // {
  // string branchnum = dtoldbranch.Rows[i].ToString();
  // } 

for (int i = 0; i < GVBranch.Rows.Count; i++)
  {
  CheckBox cbox = (CheckBox)GVBranch.Rows[i].FindControl("CheckBox1");

   
  if (GVBranch.Rows[i].Cells[1].Text.Trim().ToString() == "XXX")//怎么把dtoldbranch里的值放在这里进行判断呢?dtoldbranch里的值不止一行 {
  cbox.Checked = true;
  }
  }

------解决方案--------------------------------------------------------
把dgv那行值取出来
用dt.Rows.Contains(dgv)来判断
  相关解决方案