问题描述
protectedvoidButton1_Click(objectsender,EventArgse){intscore=0;foreach(GridViewRowdrinGridView1.Rows)//对单选题每题进行判断用户选择答案{stringstr="";if(((RadioButton)dr.FindControl("RadioButton1")).Checked){str="A";}elseif(((RadioButton)dr.FindControl("RadioButton2")).Checked){str="B";}elseif(((RadioButton)dr.FindControl("RadioButton3")).Checked){str="C";}elseif(((RadioButton)dr.FindControl("RadioButton4")).Checked){str="D";}Labellabel=(Label)GridView1.Rows[0].Cells[0].FindControl("Label4");Label7.Text=label.Text;Label3.Text=str;if(((Label)dr.FindControl("Label4")).Text.Trim()==str)//将用户选择结果和答案进行比较{score=score+2;}Label8.Text=GridView1.Rows.Count.ToString();}Response.Write("<scriptlanguage=javascript>alert('您的成绩为:"+score+"分!')</script>");}
在foreach前添加的断点,点哪个RadioButton监视后checked都是false,Gridview1.Rows为1,不是0。求问为什么选不出checked?多谢
解决方案
解决方案二:
RadioButtonautopostback属性为true吗?
解决方案三:
引用1楼guwei4037的回复:
RadioButtonautopostback属性为true吗?
属性是false,但是改成true自动就刷新了,不是点button后触发的