string examTypeWill = ds.Tables["student"].Rows[0]["examTypeWill"].ToString();
                RadioButton rbtnLiKe = new RadioButton();
                rbtnLiKe = (RadioButton)(e.Row.Cells[2].FindControl("rbtnLiKe"));
                rbtnLiKe.Checked = false;
                RadioButton rbtnWenKe = new RadioButton();
                rbtnWenKe = (RadioButton)(e.Row.Cells[2].FindControl("rbtnWenKe"));
                rbtnWenKe.Checked = false;
                RadioButton rbtnTeChang = new RadioButton();
                rbtnTeChang = (RadioButton)(e.Row.Cells[2].FindControl("rbtnTeChang"));
                rbtnTeChang.Checked = false;
                if (examTypeWill == "理科")
                {
                    rbtnLiKe.Checked = true;
                    rbtnLiKe.ForeColor = Color.Red;
                }
                else if (examTypeWill == "文科")
                {
                    rbtnWenKe.Checked = true;
                    rbtnWenKe.ForeColor = Color.Red;
                }
                else if (examTypeWill == "特长")
                {
                    rbtnTeChang.Checked = true;
                    rbtnTeChang.ForeColor = Color.Red;
                }
帮我看看为什么不能赋值啊, 我快疯掉了,马上要要的.....

解决方案 »

  1.   

    RadioButton rbtnLiKe = new RadioButton();
    rbtnLiKe = (RadioButton)(e.Row.Cells[2].FindControl("rbtnLiKe"));
    ==>
    RadioButton rbtnLike=(RadioButton)(e.Row.Cells[2].FindControl("rbtnLiKe"));试试??
      

  2.   

    错误提示:
      Message="未将对象引用设置到对象的实例。"
      

  3.   

    加限制没有?
    if(e.item.itemindex>=0)
      

  4.   

    if(e.item.itemindex>=0)
    {
    string examTypeWill = ds.Tables["student"].Rows[0]["examTypeWill"].ToString();
                    RadioButton rbtnLiKe = (RadioButton)(e.Row.Cells[2].FindControl("rbtnLiKe"));
                    rbtnLiKe.Checked = false;
                    RadioButton rbtnWenKe = (RadioButton)(e.Row.Cells[2].FindControl("rbtnWenKe"));
                    rbtnWenKe.Checked = false;
                    RadioButton rbtnTeChang = (RadioButton)(e.Row.Cells[2].FindControl("rbtnTeChang"));
                    rbtnTeChang.Checked = false;
                    if (examTypeWill == "理科")
                    {
                        rbtnLiKe.Checked = true;
                        rbtnLiKe.ForeColor = Color.Red;
                    }
                    else if (examTypeWill == "文科")
                    {
                        rbtnWenKe.Checked = true;
                        rbtnWenKe.ForeColor = Color.Red;
                    }
                    else if (examTypeWill == "特长")
                    {
                        rbtnTeChang.Checked = true;
                        rbtnTeChang.ForeColor = Color.Red;
                    }
    }
      

  5.   

    Rows[0]是什么。是不是要有个变量i呀?
      

  6.   

    检查一下你的模板列的单选按钮的name属性是否赋值了,如果不赋值就可能产生这种情况
      

  7.   

    后台,这里的问题是if(e.item.itemindex>=0) ,谢谢啊.....等会给分
      

  8.   

    还有一个问题        for (i = 0; i < countRow; i++)
            {
                
                string examTypeWill = null;
                stuSchoolID = this.gvStudent.Rows[i].Cells[0].Text.ToString();
                RadioButton rbtnLiKe = (RadioButton)(this.gvStudent.Rows[i].Cells[2].FindControl("rbtnLiKe"));
                RadioButton rbtnWenKe = (RadioButton)(this.gvStudent.Rows[i].Cells[2].FindControl("rbtnWenKe"));
                RadioButton rbtnTeChang = (RadioButton)(this.gvStudent.Rows[i].Cells[2].FindControl("rbtnTeChang"));
                try
                {
                    if (rbtnLiKe.Checked == true)
                    {
                        examTypeWill = "理科";
                    }
                    else if (rbtnWenKe.Checked == true)
                    {
                        examTypeWill = "文科";
                    }
                    else if (rbtnTeChang.Checked == true)
                    {
                        examTypeWill = "特长";
                    } 
                    cmd.CommandText = "update student set examTypeWill='" + examTypeWill + "' where stuSchoolID='" + stuSchoolID + "'";
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        countUpdate++;
                    }
                }
                catch
                {
                    errorCount++;
                }
            }
    为什么examTypeWill 始终是第一个?模板列有三个控件...rbtnLiKe,rbtnWenKe,rbtnTeChang