asp.net 性别 单选按钮 操作Radiobutton控件
1个回答
展开全部
给你举个小例子
首先拖两个Radiobutton,一个Button
<asp:RadioButton ID="RadioButton1" Text="男" runat="server" GroupName="Sex" />//text属性是Radiobutton显示的值,因为性别只能选一个,所以两个Radiobutton的GroupName是一致的
<asp:RadioButton ID="RadioButton2" Text="女" runat="server" GroupName="Sex"/>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
然后在Button的click事件中
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButton1.Checked)//说明点的是RadioButton1
{
Response.Write(RadioButton1.Text);//输出RadioButton1.Text,即男
}
if (RadioButton2.Checked)//说明点的是RadioButton1
{
Response.Write(RadioButton2.Text);//输出RadioButton1.Text,即女
}
}
首先拖两个Radiobutton,一个Button
<asp:RadioButton ID="RadioButton1" Text="男" runat="server" GroupName="Sex" />//text属性是Radiobutton显示的值,因为性别只能选一个,所以两个Radiobutton的GroupName是一致的
<asp:RadioButton ID="RadioButton2" Text="女" runat="server" GroupName="Sex"/>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
然后在Button的click事件中
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButton1.Checked)//说明点的是RadioButton1
{
Response.Write(RadioButton1.Text);//输出RadioButton1.Text,即男
}
if (RadioButton2.Checked)//说明点的是RadioButton1
{
Response.Write(RadioButton2.Text);//输出RadioButton1.Text,即女
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询