日期:2014-05-18 浏览次数:20785 次
<asp:DataList ID="DataList1" runat="server" Height="241px" Width="775px"> <ItemTemplate> <table> <tr> <td> <%#Container.ItemIndex+1 %> 、<asp:Label ID="timu" runat="server" Text='<%#Eval("question") %>'></asp:Label> </td> </tr> <tr> <td> <asp:RadioButton ID="A" runat="server" GroupName="radion" />A、<asp:Label ID="Label1" runat="server" Text='<%#Eval("A") %>'></asp:Label> <asp:RadioButton ID="B" runat="server" GroupName="radion" />B、<asp:Label ID="Label2" runat="server" Text='<%#Eval("B") %>'></asp:Label> <asp:RadioButton ID="C" runat="server" GroupName="radion" />C、<asp:Label ID="Label3" runat="server" Text='<%#Eval("C") %>'></asp:Label> <asp:RadioButton ID="D" runat="server" GroupName="radion" />D、<asp:Label ID="Label4" runat="server" Text='<%#Eval("D") %>'></asp:Label> </td> </tr> </table> </ItemTemplate> </asp:DataList>
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "submit") { for (int i = 0; i <= e.Item.Controls.Count; i++)//根据你一个有多少个选项循环多少次 { RadioButton A = (RadioButton)DataList1.Items[i].FindControl("A");//第i选题第1个选项 if (A.Checked) { Label Label1 = (Label)DataList1.Items[e.Item.ItemIndex].FindControl("Label1"); string value = Label1.Text; } RadioButton B = (RadioButton)DataList1.Items[i].FindControl("B");//第i题第2个选项 if (A.Checked) { Label Label2 = (Label)DataList1.Items[e.Item.ItemIndex].FindControl("Label2"); string value = Label2.Text; } RadioButton C = (RadioButton)DataList1.Items[i].FindControl("C");//第i题第3个选项 if (A.Checked) {