问题描述
大大们帮帮忙啊,在线等啊
解决方案
解决方案二:
stringresult="";foreach(ListItemliinthis.RadioButtonList1.Items){if(li.Selected){result=li.Text;Label.Text="提示:你選擇的答案是"+result;}}if(result!=""){if(result=="正確答案"){Label.Text="提示:正確";}else{Label.Text="提示:錯誤";}}else{Label.Text="提示:你沒有選擇答案";}
隨手寫的。
解决方案三:
protectedvoidButton1_Click(objectsender,EventArgse){foreach(DataListItemiteminDataList1.Items){RadioButtonListrbl2=(RadioButtonList)item.FindControl("RadioButtonList1");if(rbl2.SelectedIndex!=-1){this.HiddenField1.Value=rbl2.SelectedValue.ToString();}else{Response.Write("<script>alert('对不起,请选择答案!')</script>");return;}}inti=(int)ViewState["Scount"];i++;ViewState["Scount"]=i;SqlConnectionmycon=newSqlConnection("Server=(local);Database=takeawaylanguages;UID=sa;Password=sa123");mycon.Open();stringstr="select*fromexamwhereexamid="+this.PartId+"andid="+ViewState["Scount"]+"";SqlCommandmycmd=newSqlCommand(str,mycon);SqlDataReaderreader;reader=mycmd.ExecuteReader();if(reader.HasRows){Response.Write(HiddenField1.Value);DataList1.DataSource=reader;DataList1.DataBind();//mycon.Close();}else{Response.Write(bid);DataList1.Visible=false;Button1.Visible=false;Panel1.Visible=true;}}我想在这个单击事件中判断把答案要绑定到一个DATALIST中用来显示正确答案和已选的答案