我正在使用以下代码
从Code Behind生成单选按钮 var licRB = questions[QNo - 1].AnswerRadioButton.optionRB;
for (int i = 0; i < licRB.Length; i++)
{
if (licRB[i]._checked == "true")
{
stringBuilder.Append(String.Format("<input type=\"radio\" name=\"Q" + (QNo) + "AnswerRBOption\" value='{0}' title='{1}' checked=\"checked\" />{1} <br />", licRB[i].value, licRB[i].text));
}
else
{
stringBuilder.Append(String.Format("<input type=\"radio\" name=\"Q" + (QNo) + "AnswerRBOption\" value='{0}' title='{1}' />{1} <br />", licRB[i].value, licRB[i].text));
}
}
(FindControl("divQ" + QNo + "AnswerRBL") as HtmlGenericControl).InnerHtml = stringBuilder.ToString();
在提交按钮上单击选中的值将存储在数据库中,如下所示:
ARBValue = Request.Form["Q" + QNo + "AnswerRBOption"],
现在我需要从数据库中检索值并显示带有所选值的单选按钮。请告诉我最好的方法吗?
答案 0 :(得分:0)
下面的文字解决了在HTML5单选按钮列表中显示所选单选按钮的问题
(FindControl("divQ" + q.QNo + "AnswerRBL") as HtmlGenericControl).InnerHtml = q.ARBOption
.Replace("checked=\"checked\"","")
.Replace("value='"+ q.ARBValue + "'" , "value='" + q.ARBValue + "' checked=\"checked\"");