while( reader.Read())
   {
     foreach(DataGridItem dgi in datagrid.Items)
      {
        if(System.Convert.ToBoolean(reader["sex"].ToString()))
((DropDownList)dgi.FindControl("UnBind")).SelectedIndex=0;
        else
         ((DropDownList)dgi.FindControl("UnBind")).SelectedIndex=1;
      }   }
大家看看~我SEX设置为真假型(true/false),取的的值 reader["sex"] 为什么值?发现他判断的都是真值!

解决方案 »

  1.   

    reader["sex"].ToString()=="False"//这样判断,注意大小写
      

  2.   

    Actuall I suggested to change the data type from "boolean" to "int".
    Because it's dependency with both side (programming and database).
    Aim to reduce the difficult of development. That's my suggestion only.
      

  3.   

    Convert.ToBoolean(reader["sex"])把TOSTRING()去掉
      

  4.   

    ToString返回的一定是string,这是常识,怎么可能当作bool型呢?
      

  5.   

    // while( reader.Read())
    // {
    foreach(DataGridItem dgi in datagrid.Items)
    {
       
    //if(reader["sex"].ToString()=="True")
        
     ((DropDownList)dgi.FindControl("UnBind")).SelectedIndex=1;
    //else
    //  ((DropDownList)dgi.FindControl("UnBind")).SelectedIndex=0;
    } // }这个就行!为什么加上数据库读写的部分就不行了!?
      

  6.   

    什么数据库  如果是Access中的 Yes/No 类型  那么 Yes 为 -1  No 为 0