asp.net的RadioButton控件的使用
1、前台:
<asp:RadioButton ID="rbPrintNo" GroupName="AbnormalType" Text="分单" runat="server"
Checked="true" OnCheckedChanged="rbPrintNo_CheckedChanged" AutoPostBack="true" />
<asp:RadioButton ID="rbWaybill" GroupName="AbnormalType" Text="主单" runat="server"
Checked="false" OnCheckedChanged="rbWaybill_CheckedChanged" AutoPostBack="true" />
把GroupName="AbnormalType" 设置为一样的,就是把他们分组,同一组的就只能单选。
注意:一定要加属性AutoPostBack="true" ,这样才能执行后台的CheckedChanged事件。
2、后台的CheckedChanged事件:
protected void rbPrintNo_CheckedChanged(object sender, EventArgs e)
{
if (this.rbPrintNo.Checked)
{
//按分单
this.ddlTaskOrderNo.Enabled = true;
this.ddlPrintNo.Enabled = true;
this.ddlWaybill.Enabled = false;
}
else
{
//按主单
this.ddlWaybill.Enabled = true;
this.ddlTaskOrderNo.Enabled = false;
this.ddlPrintNo.Enabled = false;
}
}