当前位置:编程学习 > C#/ASP.NET >>

问卷如何循环输出

就是,一个问卷有多个问题,一个问题有多个答案,如何输出,简单点的 --------------------编程问答-------------------- 循环输出不就是把问题列表绑定到Repeater、DataList、GridView或者ListView控件上嘛! --------------------编程问答-------------------- 让我想起父Repeater,,题的ID,,里绑定子Repeater,,,这道题答案的统计=父ID --------------------编程问答--------------------
<asp:Repeater runat="server" ID="rptQuestion" OnItemDataBound="rptQuestion_ItemDataBound">
                                <ItemTemplate>
                                    <ul  class="questionUL">
                                        <li>
                                            <%# Container.ItemIndex + 1%>、<asp:Label ID="lblTitle" runat="server" Text='<%#Eval("title") %>'></asp:Label> 
                                            
                                            <ul class="optionLI">
                                            <asp:Repeater runat="server" ID="rptOption" OnItemDataBound="rptOption_ItemDataBound">
                                <ItemTemplate>
                                                <li id="option_li" runat="server">
                                                
                                                </li>
                                                </ItemTemplate>
                                                </asp:Repeater>
                                            </ul>
                                        </li>
                                    </ul>
                                </ItemTemplate>
                            </asp:Repeater>

protected void rptOption_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView drv = e.Item.DataItem as DataRowView;
            string type= drv["option_type"].ToString();
           

            HtmlGenericControl html= (HtmlGenericControl) e.Item.FindControl("option_li") ;
          
            if (type=="单选题")
            {
                RadioButton rb = new RadioButton();
                rb.GroupName = "id1";
                rb.ID = "rbOption";
                rb.Text = drv["title"].ToString();
             
                html.Controls.Add(rb);
            }
            if (type == "多选题")
            {
                CheckBox cb = new CheckBox();
                cb.ID = "cbkOption";
                cb.Text = drv["title"].ToString();
                html.Controls.Add(cb);
            }
            if (type == "判断题")
            {

            }
            if (type == "问答题")
            {

            }

        }
    }
--------------------编程问答-------------------- 数据放在List<string>中  生成随机数调用(根据List<string>的总共记录数),调用后在List<string>中根据当前下标移除当前数据
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,