如何解决如何创建带有提交问题的新单选按钮列表? c#asp.net
| 我有:<div id=\"question\">
<div style=\"float: left; width: 250px;\">
<asp:Label ID=\"question\" runat=\"server\"></asp:Label></div>
<div>
<asp:RadioButtonList ID=\"selectdYesNo\" runat=\"server\" RepeatDirection=\"Horizontal\">
<asp:ListItem Text=\"Yes\" Value=\"1\"></asp:ListItem>
<asp:ListItem Text=\"No\" Value=\"0\"></asp:ListItem>
</asp:RadioButtonList>
</div>
</div>
<div id=\"btCreate\" style=\"margin-left: 200px; margin-top: 10px;\">
<asp:Button runat=\"server\" Text=\"Categorize\" ID=\"btCategorize\" />
</div>
提交后如何创建带有新问题的单选按钮列表的新条目?即时创建新的2、3、4等。
解决方法
这是你的代码
protected void Page_Load(object sender,EventArgs e)
{
if (!IsPostBack)
{
PanelFirstQuestionBlock.Visible = true;
}
}
protected void FirstQuestionGotAnswered(object sender,EventArgs e)
{
PanelFirstQuestionBlock.Visible = false;
PanelSecondQuestionBlock.Visible = true;
}
这是您的ASP:HTML
<asp:Panel ID=\"PanelFirstQuestionBlock\" runat=\"server\" Visible=\"false\">
<h1>My first Question</h1>
<asp:RadioButtonList ID=\"RadioButtonListAnswer1\" runat=\"server\"
OnSelectedIndexChanged=\"FirstQuestionGotAnswered\">
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>no</asp:ListItem>
</asp:RadioButtonList>
</asp:Panel>
<asp:Panel ID=\"PanelSecondQuestionBlock\" runat=\"server\" Visible=\"false\">
<h1>My second Question</h1>
<asp:RadioButtonList ID=\"RadioButtonListAnswer2\" runat=\"server\">
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>no</asp:ListItem>
</asp:RadioButtonList>
</asp:Panel>
, 你可以这样尝试selectdYesNo.Items.Add(new ListItem(\"text\",\"value\"));
, 您应该在以下之间放置第三个条目:
<%
if (needToShowThirdEntry) {
%>
和
<%
}
%>
因此,您的代码:
<asp:RadioButtonList ID=\"selectdYesNo\" runat=\"server\" RepeatDirection=\"Horizontal\">
<asp:ListItem Text=\"Yes\" Value=\"1\"></asp:ListItem>
<asp:ListItem Text=\"No\" Value=\"0\"></asp:ListItem>
<%
if (needToShowThirdEntry) {
%>
<asp:ListItem Text=\"Maybe\" Value=\"2\"></asp:ListItem>
<%
}
%>
</asp:RadioButtonList>
更新
当您更新问题时,我的新答案将是:
<asp:RadioButtonList ID=\"selectdYesNo\" runat=\"server\" RepeatDirection=\"Horizontal\">
<asp:ListItem Text=\"Yes\" Value=\"1\"></asp:ListItem>
<asp:ListItem Text=\"No\" Value=\"0\"></asp:ListItem>
</asp:RadioButtonList>
<%
if (needToShowSecondList) {
%>
<asp:RadioButtonList ID=\"newRBList\" runat=\"server\" RepeatDirection=\"Horizontal\">
<asp:ListItem Text=\"Yes\" Value=\"1\"></asp:ListItem>
<asp:ListItem Text=\"No\" Value=\"0\"></asp:ListItem>
<asp:ListItem Text=\"Maybe\" Value=\"2\"></asp:ListItem>
</asp:RadioButtonList>
<%
}
%>
但是,由于这是单独的列表,因此应该制作普通的单选按钮列表(如果没有),并使用后面代码中的newRBList.Visible
属性在第一次渲染时将其隐藏(回发之前)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。