繁体   English   中英

如何创建新的radiobuttonlist与提交问题? c#asp.net

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM