radiobutton嵌套在datalist里面不能单选
如题我做了一个像考试卷一样的选择题(单选)1.XXXXXXXXXXXXXa.1b.2c.3d.42.XXXXXXXXXXXXXa.1b.2c.3d.43.XXXXXXXX...
如题
我做了一个像考试卷一样的选择题(单选)
1.XXXXXXXXXXXXX
a.1 b.2 c.3 d.4
2.XXXXXXXXXXXXX
a.1 b.2 c.3 d.4
3.XXXXXXXXXXXXX
a.1 b.2 c.3 d.4
如上所述,我用datalist嵌套一个radiobutton,然后从数据库里拿出值来给radiobutton绑定,但是不用进行每道题的单选,请问有没有这方面的代码,网上的代码我找了很久都搞不行。
groupname在datalist下面是没用的,我试过很多次,我最后用的是JS的方法控制按钮的,最后遍历出来,基本已经搞定!多谢各位了 展开
我做了一个像考试卷一样的选择题(单选)
1.XXXXXXXXXXXXX
a.1 b.2 c.3 d.4
2.XXXXXXXXXXXXX
a.1 b.2 c.3 d.4
3.XXXXXXXXXXXXX
a.1 b.2 c.3 d.4
如上所述,我用datalist嵌套一个radiobutton,然后从数据库里拿出值来给radiobutton绑定,但是不用进行每道题的单选,请问有没有这方面的代码,网上的代码我找了很久都搞不行。
groupname在datalist下面是没用的,我试过很多次,我最后用的是JS的方法控制按钮的,最后遍历出来,基本已经搞定!多谢各位了 展开
展开全部
datalist里面的代码:
<asp:DataList ID="DataList1" runat="server" Width="402px">
<ItemTemplate>
<table border="0" cellspacing="0" style="width: 240px">
<tr>
<td style="width: 200px">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("productid") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton1" runat="server" groupname="nice" Width="10px" />A:<asp:Label
ID="Label2" runat="server" Text='<%# Eval("productid") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton2" runat="server" Width="10px" GroupName="nice" />B:<asp:Label
ID="Label3" runat="server" Text='<%#Eval("productname") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton3" runat="server" Width="10px" GroupName="nice" />C:<asp:Label
ID="Label4" runat="server" Text='<%# Eval("supplierid")%>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton4" runat="server" Width="10px" GroupName="nice" />D:<asp:Label
ID="Label5" runat="server" Text='<%# Eval("unitprice") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
后台代码:
protected void Page_Load(object senderv, EventArgs e)
{
string sqlconn = "server=.;database=northwind;uid=sa;pwd=amigo";
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
string sqlcomd = "select top 10 productid,productname,supplierid,unitprice from products";
SqlDataAdapter da = new SqlDataAdapter(sqlcomd,conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
conn.Close();
}
<asp:DataList ID="DataList1" runat="server" Width="402px">
<ItemTemplate>
<table border="0" cellspacing="0" style="width: 240px">
<tr>
<td style="width: 200px">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("productid") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton1" runat="server" groupname="nice" Width="10px" />A:<asp:Label
ID="Label2" runat="server" Text='<%# Eval("productid") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton2" runat="server" Width="10px" GroupName="nice" />B:<asp:Label
ID="Label3" runat="server" Text='<%#Eval("productname") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton3" runat="server" Width="10px" GroupName="nice" />C:<asp:Label
ID="Label4" runat="server" Text='<%# Eval("supplierid")%>'></asp:Label></td>
</tr>
<tr>
<td style="width: 200px; text-align: left">
<asp:RadioButton ID="RadioButton4" runat="server" Width="10px" GroupName="nice" />D:<asp:Label
ID="Label5" runat="server" Text='<%# Eval("unitprice") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
后台代码:
protected void Page_Load(object senderv, EventArgs e)
{
string sqlconn = "server=.;database=northwind;uid=sa;pwd=amigo";
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
string sqlcomd = "select top 10 productid,productname,supplierid,unitprice from products";
SqlDataAdapter da = new SqlDataAdapter(sqlcomd,conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
conn.Close();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询