首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-04-19 
如何判断gridview里某一行的值是否在datatable中string ConnString SqlConnection srcConnection n

如何判断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)来判断

热点排行