我正在尝试在ASP.Net项目中创建调查。 我的调查基于JSON模型。这是我的模特:
public class Test
{
public string testName { get; set; }
public List<ScoreSubject> scoreSubjects { get; set; }
public List<Block> blocks { get; set; }
}
public class Block
{
public string blockName { get; set; }
public string bodyTitle { get; set; }
public string bodyText { get; set; }
public string concludingText { get; set; }
public List<Question> questions { get; set; }
}
public class Question
{
public int questionId { get; set; }
public bool required { get; set; }
public string questionTextAboveAnswers { get; set; }
public string questionTextBelowAnswers { get; set; }
public string warningText { get; set; }
public string scoreSubject { get; set; }
public List<Answer> answers { get; set; }
}
public class Answer
{
public int answerId { get; set; }
public string answerText { get; set; }
public int score { get; set; }
public string warningText { get; set; }
public int skipQuestions { get; set; }
}
我有3个街区,每个都有一些问题。我试图做的是在小组中显示答案。单击按钮:呈现下一个问题。
这是我的usercontrol的一部分:
public List<RootNode> rootNode;
int _CounterBlock;
int _CounterQuestions;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
_CounterBlock = 0;
_CounterQuestions = 0;
}
LoadJson(); //Convert JSON data to models
SetControls();
populateDataByIndex();
}
private void SetControls()
{
testPanel.Visible = true;
ProceedLanguageButton.Visible = true;
QuestionsLanguageRadioButtonList.Visible = false;
}
public void populateDataByIndex()
{
Rootnode list = rootNode.First(); //Always 1st item in array
//Get block by index
Block block = list.test.blocks[_CounterBlock];
//Load next block when there are no answers, or last answer is filled
if((_CounterQuestions >= block.questions.Count) || block.questions.Count < 0)
{
_CounterBlock++;
_CounterQuestions = 0;
}
bodyTitle.Text = block.bodyTitle;
bodyText.Text = block.bodyText;
if(block.questions.Count > 0)
{
//Show list when questions is not null
QuestionsLanguageRadioButtonList.Visible = true;
//Remove existing items from list
QuestionsLanguageRadioButtonList.Items.Clear();
//Show label and question
Question question = block.questions[_CounterQuestions];
questionLabel.Text = question.questionTextAboveAnswers;
foreach(var answer in question.answers)
{
QuestionsLanguageRadioButtonList.Items.Add(new ListItem() { Text = answer.answerText, Value = answer.score.ToString() });
}
}
}
但是,这总是显示我的第一个块。我怎样才能在这里实现“分页”?我尝试使用Session
,但这在usercontrol中不可用。
这是我的小组:
<asp:Panel runat="server" ID="TestPanel" DefaultButton="ProceedLanguageButton">
<div>
<h1><asp:Label runat="server" ID="bodyTitle"></asp:Label></h1>
</div>
<div>
<asp:Label runat="server" id="bodyText"></asp:Label>
</div>
<div>
<asp:Label runat="server" ID="questionLabel"></asp:Label>
</div>
<div>
<cc1:languageradiobuttonlist id="QuestionsLanguageRadioButtonList" runat="server" repeatdirection="Vertical" basekey="Questions" />
</div>
<div>
<asp:Label runat="server" id="concludingText"></asp:Label>
</div>
</asp:Panel>
<div class="contentSeperator"></div>
<%--BUTTONS--%>
<div>
<cc1:LanguageButton runat="server" ID="ReturnLanguageButton" CssClass="defaultButton Actie"
CausesValidation="false" OnClick="ReturnLanguageButton_Click" Key="Test:Return" />
<cc1:LanguageButton runat="server" ID="ProceedLanguageButton" CssClass="defaultButton Proceed"
CausesValidation="false" OnClick="ProceedLanguageButton_Click" Key="Test:Proceed" />
</div>
注意:这不是MVC项目。
有人能指出我正确的方向吗?提前谢谢。