if (Convert.ToBoolean(dt.Rows[0][16].ToString()) ==true)
            {
                this.CheckBox1.Checked= true;
               
             
            }
            else
            {
                this.CheckBox1.Checked = false;
            }页面上的checkbox的默认值是false的,现在判断bit列的值,如果是true,那this.CheckBox1.Checked是true,上面的写法有哪个地方不对,在线等。谢谢~列值为:
8 2011-06-11  2011-06-15 1 23121321231 aasdfasdf  asf 2334 gsdgsdfg afsf 234234234  hfdgdh 4 123123.00   50    gssdgsdg保证金   1 NULL NULL NULL NULL NULL
后面6列为bit类型。。

解决方案 »

  1.   

    if (dt.Rows[0][16].ToString() =="1")
      

  2.   

    bit  1代表true  0代表false
      

  3.   

    谢谢,但是我调试的时候
    if (dt.Rows[0][16].ToString()) ==“1”)
      {
      this.CheckBox1.Checked= true;//没有运行!
        
        
      }
      else
      {
      this.CheckBox1.Checked = false;//这里运行了!
      }
     。。
      {
      this.CheckBox1.Checked= true;
        
        
      }这个地方没有运行呢!我试过了好多方法,都不行,确定的是checkbox的checked原值是false,
      

  4.   

    你这个方法在哪个事件里写的。。如果是CheckBox的事件 要设置AotuPostBack=true
      

  5.   

    也不是哪个事件里
    是这样,我在gridview里面有n条记录,其中后面几个就是bit类型,然后选中某条记录,用几个checkbo来显示后面几个bit类型的状态,如果bit类型的值为true,那么相对应的checkbo的checked为true,不知道这样说明白不?
      

  6.   

    判断是写在这个事件里面,为什么取不到值呢?protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int a = 0;
            int i = this.GridView1.SelectedIndex;//获得索引
            if (a <= i)
            {
                //int b = this.GridView1.Rows[i].Cells[0].Text;
                string b = this.GridView1.Rows[i].Cells[0].Text.ToString();
                PublicClass pbl = new PublicClass();
                DataTable dt = new DataTable();
                dt = pbl.MySqlDataTable("select * from chs where CLH='" + b + "'");            this.ywbh.Text = dt.Rows[0][0].ToString();
                this.sqrq.Text = dt.Rows[0][1].ToString();
                this.chgs.Text = dt.Rows[0][5].ToString();
                this.clh.Text = dt.Rows[0][10].ToString();
                this.name.Text = dt.Rows[0][6].ToString();
                this.slbh.Text = dt.Rows[0][4].ToString();
                this.jzmj.Text = dt.Rows[0][13].ToString();
                this.fwzl.Text = dt.Rows[0][8].ToString();
                this.dzwd.Text = dt.Rows[0][11].ToString();
                this.yfwzl.Text = dt.Rows[0][9].ToString();
                this.TextBox11.Text = dt.Rows[0][15].ToString();
                this.zcs.Text = dt.Rows[0][12].ToString();
                this.bzj.Text = dt.Rows[0][14].ToString();
                if (dt.Rows[0][16].ToString() == "1")//这里取不到值            {
                    this.CheckBox2.Checked = true;//不运行
                }
                else//所有if判断都跳转到这里
                {
                    this.CheckBox2.Checked = false;
                }
                if (dt.Rows[0][17].ToString() == "1")
                {
                    this.CheckBox3.Checked = true;
                }
                else
                {
                    this.CheckBox3.Checked = false;
                }
                if (dt.Rows[0][18].ToString() == "1")
                {
                    this.CheckBox4.Checked = true;
                }
                else
                {
                    this.CheckBox4.Checked = false;
                }
                if (dt.Rows[0][19].ToString() == "1")
                {
                    this.CheckBox5.Checked = true;
                }
                else
                {
                    this.CheckBox5.Checked = false;
                }
                if (dt.Rows[0][20].ToString() == "1")
                {
                    this.CheckBox6.Checked = true;
                }
                else
                {
                    this.CheckBox6.Checked = false;
                }
                this.CheckBox2.Checked = true;        }
            tip.Style.Add("display", "none");
        }请问问题出在什么地方?
      

  7.   

    bit 0或1不是字符串吧,==1或0试试
      

  8.   

    你没找到控件,像这样一样TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1"); 先把你的checkbox控件找到 赋值就行; 
      

  9.   

    你调试下,在”if (dt.Rows[0][16].ToString() == "1")“判断这里插入个断点,看看dt.Rows[0][16].ToString() 到底返回个什么值,再把对比条件改改就行啦撒。