如何在页面加载后保留一个包含已保存条目的列表?
我有一个列表:
public List<string> QuestionIDs;
构造函数:
public EmployeeCategorizationControl()
{
QuestionIDs = new List<string>();
}
很多这样的单选按钮:
<asp:RadioButtonList ID="selectedYesNo1" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="FirstQuestionGotAnswered">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
我试图将 QuestionID 保存在列表中:
protected void FirstQuestionGotAnswered(object sender, EventArgs e)
{
QuestionID = selectedYesNo1.Text;
QuestionIDs.Add(QuestionID);
}
我的问题是,页面加载后,当我根据上一个问题的 id 调用下一个问题时,列表中没有 ID全部。我应该如何保存 Id 以便在 page_load 之后使用它们?
i have a list:
public List<string> QuestionIDs;
constructor:
public EmployeeCategorizationControl()
{
QuestionIDs = new List<string>();
}
lots of radio buttons like this:
<asp:RadioButtonList ID="selectedYesNo1" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="FirstQuestionGotAnswered">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
i am trying to save QuestionID in List here:
protected void FirstQuestionGotAnswered(object sender, EventArgs e)
{
QuestionID = selectedYesNo1.Text;
QuestionIDs.Add(QuestionID);
}
my problem is that after page load when i calling next question based on id of previous, there are no ID in list at all. how schould i save Id for to use them after page_load?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将列表放入视图状态中
You'll have to put the list in the Viewstate