Reputation: 7153
i have:
<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>
how can i create new entry of radiobuttonlist with new question after submit?? im princip create new 2, 3, 4 etc.
Upvotes: 0
Views: 1608
Reputation: 11116
here is your code
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;
}
here your 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>
Upvotes: 2
Reputation: 9051
You should place third entry between:
<%
if (needToShowThirdEntry) {
%>
and
<%
}
%>
So, your code:
<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>
UPDATE As you updated your question, my new answer would be:
<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>
<%
}
%>
But, as this is separate list, you should make normal radio button list (without if) and use newRBList.Visible
property from code behind to hide it on first rendering (before postback)
Upvotes: 0
Reputation: 6446
you can try like this selectdYesNo.Items.Add(new ListItem("text","value"));
Upvotes: 0