各位高手,小弟现遇到一个问题前台单选框
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" />正确</td><td width="5%">
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="N" />错误</td>如何使其通过后台数据库读取的数据,使单选框选中啊比如后台读取的是“true”
则前台单选框value=“Y”的选中,
数据库读取的“false”
则前台单选框value=“N”的选中我知道有ASP的可以
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" <%if rs("hot") ="true" then Response.write("checked")%> />
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="N" <%if rs("hot") ="false" then Response.write("checked")%> />请问换成.NET的 怎么写啊
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" />正确</td><td width="5%">
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="N" />错误</td>如何使其通过后台数据库读取的数据,使单选框选中啊比如后台读取的是“true”
则前台单选框value=“Y”的选中,
数据库读取的“false”
则前台单选框value=“N”的选中我知道有ASP的可以
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" <%if rs("hot") ="true" then Response.write("checked")%> />
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="N" <%if rs("hot") ="false" then Response.write("checked")%> />请问换成.NET的 怎么写啊
<% if(true){%>
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" checked="checked" />正确</td><td width="5%">
<%}else
{%>
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" />正确</td><td width="5%">
<%}%>
<asp:Repeater ID="rptSubjectOfJudgeList" runat="server" >
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" class="tableList" width="960">
</HeaderTemplate>
<ItemTemplate>
<tr >
<td >
<asp:HiddenField ID="hidJudgeID" runat="server" Value='<%#Eval("ID") %>'/>
(<%#Eval("Index")%>) <%#Eval("Question")%>
<td width="5%">
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" checked="<%=Headself%>" />正确</td><td width="5%">
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="N" checked="<%=Headself%>" />错误</td> </td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
前台写了个"<%=Headself%>" 可是没办法判断 一打开网页都是错误的单选被选中 库里明明是true
我知道我后台也写的乱 自己都绕迷糊了
<input name="YCBbox" type="radio" value="N"<%#Convert.ToBoolean(Eval("hot"))==false?" checked":""%>/>错误</td>
我后台是
int testID = Helper.GetUrlParmValue("testID");//考卷ID
int paperID = Helper.GetUrlParmValue("paperID");
int paperType = Helper.GetUrlParmValue("paperType");//考题类型
int recorderID = Helper.GetUrlParmValue("recorderID");//考生ID
if ((PaperType)paperType == PaperType.BySelection)//手工选题
{
PaperByManualSelection paper = new BLLPaperByManuaSelection().GetPaper(testID, paperID, recorderID);//得到判断、单选、多选的分数和答案
if (paper != null)
{
rptSubjectOfJudgeList.DataSource = paper.JudgeList; //判断题的Repeater
rptSubjectOfJudgeList.DataBind();
lblJudgeListCount.Text = paper.JudgeList.Count.ToString();//共几道题
if (paper.JudgeList.Count > 0)
{
lblJudgeScores.Text = paper.JudgeList[0].Scores.ToString();//每题分数
lblJudgeTotalScores.Text = (paper.JudgeList[0].Scores * paper.JudgeList.Count).ToString();//判断题总分
//try
//{
// foreach (SubjectOfJudge subject in paper.JudgeList)
// {
// AnswerByTester = subject.AnswerByTester;//数据库读取的答案
// }
//}
//catch
//{ } } rptSubjectOfSingleSelectionList.DataSource = paper.SingleSelectionList;//单选题
rptSubjectOfSingleSelectionList.DataBind();
lblSingleSelectionCount.Text = paper.SingleSelectionList.Count.ToString();
if (paper.SingleSelectionList.Count > 0)
{
lblSingleSelectionScores.Text = paper.SingleSelectionList[0].Scores.ToString();
lblSingleSelectionTotalScores.Text = (paper.SingleSelectionList[0].Scores * paper.SingleSelectionList.Count).ToString();
}
rptSubjectOfMultiSelectionList.DataSource = paper.MultiSelectionList;//多选题
rptSubjectOfMultiSelectionList.DataBind();
lblMultiSelectionCount.Text = paper.MultiSelectionList.Count.ToString();
if (paper.MultiSelectionList.Count > 0)
{
lblMultiSelectionScores.Text = paper.MultiSelectionList[0].Scores.ToString();
lblMultiSelectionTotalScores.Text = (paper.MultiSelectionList[0].Scores * paper.MultiSelectionList.Count).ToString();
}
lblTotalScores.Text = (Convert.ToInt32(lblJudgeTotalScores.Text)//试卷总分
+ Convert.ToInt32(lblSingleSelectionTotalScores.Text)
+ Convert.ToInt32(lblMultiSelectionTotalScores.Text)).ToString();
}
//创建考试对应的答案记录
//new BLLTestRecorder().CreateTestRecorderAnswer(Helper.GetUrlParmValue("recorderID"));
// new BLLTestRecorder().CreateTestRecorderAnswer(Helper.GetUrlParmValue("recorderID"), paper.JudgeList, paper.SingleSelectionList, paper.MultiSelectionList);
}可是前台没有能选中的
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" "<%#Convert.ToBoolean(Eval("AnswerByTester"))==true?" checked":""%>" />正确</td><td width="5%">
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="N" "<%#Convert.ToBoolean(Eval("AnswerByTester"))==false?" checked":""%>" />错误</td>
而前台比较的true全小写,我吧true也改成大写T后 提示编译错误:当前上下文中不存在名称“True”
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" "<%#Eval("AnswerByTester")=="True"?" checked":""%>" />正确</td><td width="5%">后 打开页面 依然是什么都没选中
你后台返回的值如果不是boolean型的数据就要加引号判断
那你就<%#Eval("AnswerByTester").ToString()=="True"?" checked":""%>
试试这样
<input name="YCBbox<%#Eval("ID") %>" type="radio" value="Y" checked="<%#Eval("AnswerByTester")=="True"?true:false%>" />正确</td><td width="5%">
单选题都选的D
多选还没弄
库里读出的数据明明是true 前台显示的也是true 可是radio就是一直选中最后一个radio选项“错误”
单选也是,库里是A 前台读取也是A ,但radio就一直选D 都是选最后一个radio