RadioButton取值并插入数据库

这篇博客介绍如何在ASP.NET中使用C#代码从数据库获取问题和选项,并在Repeater控件中显示。通过`Page_Load`事件加载数据,使用`SqlCommand`查询SQL数据库,将查询结果绑定到Repeater,再用RadioButton展示每个问题的四个选项。页面代码展示了RadioButton的设置,每个选项的value属性绑定到数据库中的相应答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c#代码(用于Repeater1显示题目和选项):
protected void Page_Load(object sender, EventArgs e)
    {
        string connstring = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
        SqlConnection wtConn = new SqlConnection(connstring);
        wtConn.Open();
        SqlCommand Command = new SqlCommand("select qus,auc01,auc02,auc03,auc04 from wenti", wtConn);
        SqlDataReader reader = Command.ExecuteReader();
        Repeater1.DataSource = reader;
        Repeater1.DataBind();
        reader.Close();
        wtConn.Close();
    }
---------------------------------------------------------------------------
asp.net页面代码:
<asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
<!--问题-->
<%# Eval("qus") %>
<!--选项-->
                <asp:RadioButton ID="RadioButton1" GroupName="rb" runat="server" Text="A" value='<%# Eval("aus01") %>' />
                <asp:RadioButton ID="RadioButton2" GroupName="rb" runat="server" Text="B" value='<%# Eval("aus02") %>' />
                <asp:RadioButton ID="RadioButton3" GroupName="rb" runat="server" Text="C" value='<%# Eval("aus03") %>' />
                <asp:RadioButton ID="RadioButton4" GroupName="rb" runat="server" Text="D" value='<%# Eval("aus04") %>' />
            </ItemTemplate>
        </asp:Repeater>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值