c#中如何获取Radiobutton的值

来源:百度知道 编辑:UC知道 时间:2024/09/23 05:30:35
我把两个Radiobutton放在一个组里..一个是男.一个是女..我想点击一个提交按钮后保存到数据库中.....数据库中字段类型为bit, 怎么把Radiobutton的值转换保存???

应该是用“RadioButtonList ”,
.ASPX
<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="True">男</asp:ListItem>
<asp:ListItem Value="False">女</asp:ListItem>
</asp:RadioButtonList>
.CS
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
bool sex = Convert.ToBoolean(RadioButtonList1.SelectedValue);
}

cmd.Parameters.Add("@Parameter1", System.Data.SqlDbType.Bit).Value = this.RadioButton1.Checked;