日期:2014-05-17 浏览次数:20436 次
<body> <form id="form1" runat="server"> <div style="text-align:left"> <table> <% System.Collections.Generic.IList<Topic> list = GetAllTopic(); for (int i = 0; i < list.Count; i++) { Topic topic = list[i]; Label1.Text = topic.题号 + "," + topic.内容; %> <tr> <td colspan="2"><asp:Label ID="Label1" runat="server"></asp:Label></td> </tr> <% switch (topic.类型) { case "单选": for (int j = 0; j < topic.选项.Count; j++) { RadioButton1.Text = topic.选项[j].选项 + "," + topic.选项[j].内容; %> <tr> <asp:Panel ID="Panel1" runat="server"> <td style="width:20px"></td> <td><asp:RadioButton ID="RadioButton1" runat="server"></asp:RadioButton></td> </asp:Panel> </tr> <% } break; case "多选": for (int j = 0; j < topic.选项.Count; j++) { CheckBox1.Text = topic.选项[j].选项 + "," + topic.选项[j].内容; %> <tr> <td style="width:20px"></td> <td><asp:CheckBox ID="CheckBox1" runat="server" /></td> </tr> <% } break; default: %> <tr> <td style="width:20px"></td> <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td> </tr> <% break; } } %> </table> </div> </form> </body>
/// <summary> /// 获取题的集合 /// </summary> /// <returns>题目集合</returns> protected IList<Topic> GetAllTopic() { IList<Topic> list = new List<Topic>(); SqlDataReader dr1 = DBHelper.ExecuteQuery("select 题号,类型,内容 from 题目 order by 题号"); while (dr1.Read()) { Topic topic = new Topic(); topic.内容 = dr1["内容"].ToString(); topic.类型 = dr1["类型"].ToString(); topic.题号 = int.Parse(dr1["题号"].ToString()); IList<Option> options = new List<Option>(); SqlDataReader dr2 = DBHelper.ExecuteQuery("select 题号,选项,内容 from 选项 where 题号 = " + topic.题号); while (dr2.Read()) { Option option = new Option();