if (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()))

解决方案 »

  1.   

    dr.FindControl("Label92")).Text 1有可能 dr 为NULL, 2有可能找不到Label92
      

  2.   


    前面用过dr的了,label92在页面中也有的啊
      

  3.   

    if (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()))--既然你用parse不用TryParse我假设你用framework1.1,反正要try catch一下,也不用判断控件有没有了,改写成bool b=false;
    try{b= (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()));}
    catch{}
    if(b)
    ...后边写你原来的代码
      

  4.   


    if(dr != null)
    {
      TextBox TextBoxa = (TextBox)dr.FindControl("Label92");
      string a=TextBoxa.trim.Tostring() if (str == bool.Parse("+a+")  )
      {  }
    }
      

  5.   


    if(dr != null)
    {
      TextBox TextBoxa = (TextBox)dr.FindControl("Label92");
      string a=TextBoxa.Text.Tostring() if (str == bool.Parse("+a+")  )
      {  }
    }
      

  6.   

    我try一下看看,不懂再来请教各位!
      

  7.   

    你要在gridview的行里面使用findcontrol方法,换句话说,你要知道行的索引
    Label TextBoxa = (Label)this.dr.row[index].FindControl("Label92");
      

  8.   

    gridview1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("xxx")
      

  9.   

    如果不指定行的Index,简单的写gridview1.findcontrol("xxx"),IDE并不知道要找哪个控件所以要指定行号.
      

  10.   

    if (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()))
    转换的时候不要用Text。trim(),
    text为空的话,再trim就会错
      

  11.   

    try 了,但是还是不行!大家还有什么建议不
      

  12.   

    dr 是GridViewRow 的局部变量
      

  13.   

    foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案
            {
                bool str = false;
                if (((CheckBox)dr.FindControl("CheckBox5")).Checked)
                {
                    str = true;
                }            if (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()))
                {
                    score = score + judge;
                }
           }整个代码是这样的
      

  14.   

    foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案 
            { 
                if (((CheckBox)dr.FindControl("CheckBox5")).Checked) 
                { 
                Label lbl= (Label)dr.FindControl("Label92");
                if(bool.Parse(lbl.Text.Trim())) 
                { 
                    score = score + judge; 
                } 
              }
          } 
    调试看看