【发布时间】:2016-01-13 20:22:10
【问题描述】:
我正在尝试使用 ASP.Net 和 C# 制作问卷 它是一个问题列表,根据每个答案会出现另一个问题(例如,这是 X 还是 Y?如果您从单选按钮列表中选择 X,您将收到另一个问题“x 的颜色是什么”,如果您选择 Y“hos快是Y")
到目前为止,我制作了大约 7 个带有单选按钮列表(问题数量)的标签,将它们设置为不可见,并根据第一个问题的答案,我使第二个标签和单选按钮列表可见,并更改文本到我想要的问题。
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) //first question
{
//selected value =0 => No || selected value= 1 => Yes
if (RadioButtonList1.SelectedValue == "1")
{
Label1.Visible = true;
Label1.Text = "Question number 2 based on answer a"; //show the second question
RadioButtonList2.Visible = true; //show the second question options
}
else {
Label1.Text = "Question number 2 based on answer b";
Label1.Visible = true; //show the second question
RadioButtonList2.Visible = true; //show the second question options
}
}
protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e) //2nd question
{
if (RadioButtonList1.SelectedValue == "1" && RadioButtonList2.SelectedValue == "1") //1st question answer was yes &2nd is yes
{
//some logic here
}
到目前为止,这种逻辑运行良好,但还有比这更简洁的逻辑吗? 例如,在回答完第 7 题后,我在第 4 题中进行了修改,我怎样才能使已回答的问题(5,6,7)再次清除和隐藏?!!!
【问题讨论】: