[英]How to create new radiobuttonlist with question on submit? 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>
如何在提交后用新問題創建radiobuttonlist的新條目? im princip創建新的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>
你應該在第三個條目之間放置:
<%
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>
<%
}
%>
但是,因為這是單獨的列表,你應該制作正常的單選按鈕列表(沒有if)並使用后面代碼中的newRBList.Visible
屬性在第一次渲染時隱藏它(在回發之前)
你可以試試這個selectdYesNo.Items.Add(new ListItem("text","value"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.