未将对象引用设置到对象的实例。 if (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim())) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dr.FindControl("Label92")).Text 1有可能 dr 为NULL, 2有可能找不到Label92 前面用过dr的了,label92在页面中也有的啊 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)...后边写你原来的代码 if(dr != null){ TextBox TextBoxa = (TextBox)dr.FindControl("Label92"); string a=TextBoxa.trim.Tostring() if (str == bool.Parse("+a+") ) { }} if(dr != null){ TextBox TextBoxa = (TextBox)dr.FindControl("Label92"); string a=TextBoxa.Text.Tostring() if (str == bool.Parse("+a+") ) { }} 我try一下看看,不懂再来请教各位! 你要在gridview的行里面使用findcontrol方法,换句话说,你要知道行的索引Label TextBoxa = (Label)this.dr.row[index].FindControl("Label92"); gridview1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("xxx") 如果不指定行的Index,简单的写gridview1.findcontrol("xxx"),IDE并不知道要找哪个控件所以要指定行号. if (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()))转换的时候不要用Text。trim(),text为空的话,再trim就会错 try 了,但是还是不行!大家还有什么建议不 dr 是GridViewRow 的局部变量 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; } }整个代码是这样的 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; } } } 调试看看 求助,如何把在C#textbox text数据串 保存在excel相应的cell里面 在LABEL的时候运行可以,但是在textbox中就不可以了 WinForm字体设置 字符串问题 C#打印自动分页 DataRowState没有发生改变 过程与方法的区别 关于类的继承的问题 下指令让它执行某个参数 , 如我在 开始 \ 执行 输入 C:\test\setup.exe /w 和SQL有关的一个问题! GridView的模板列如何绑定到数据库表的某个字段,如何获取模板列中某个单元的值!!!!!新手!!说详细点!谢谢! 标注式提示窗口
前面用过dr的了,label92在页面中也有的啊
try{b= (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()));}
catch{}
if(b)
...后边写你原来的代码
if(dr != null)
{
TextBox TextBoxa = (TextBox)dr.FindControl("Label92");
string a=TextBoxa.trim.Tostring() if (str == bool.Parse("+a+") )
{ }
}
if(dr != null)
{
TextBox TextBoxa = (TextBox)dr.FindControl("Label92");
string a=TextBoxa.Text.Tostring() if (str == bool.Parse("+a+") )
{ }
}
Label TextBoxa = (Label)this.dr.row[index].FindControl("Label92");
转换的时候不要用Text。trim(),
text为空的话,再trim就会错
{
bool str = false;
if (((CheckBox)dr.FindControl("CheckBox5")).Checked)
{
str = true;
} if (str == bool.Parse(((Label)dr.FindControl("Label92")).Text.Trim()))
{
score = score + judge;
}
}整个代码是这样的
{
if (((CheckBox)dr.FindControl("CheckBox5")).Checked)
{
Label lbl= (Label)dr.FindControl("Label92");
if(bool.Parse(lbl.Text.Trim()))
{
score = score + judge;
}
}
}
调试看看