使用其他条件启用/禁用基于Radiobuttonlist的Asp.net控件
亲爱的朋友们,
我正在使用Asp.net,c#,SqlServer 2005.
我有两个Textboxes FromDate和ToDate,我有两个Dropdwonlist列表,包括Month&年。
我的网页上有Radiobuttonlist,在这里我有两个带启用选项的项目。
当我选择一个选项启用时,它应该启用两个日期文本框和DISABLE两个下拉列表。
当我选择第二个选项启用时,它应该启用两个下拉列表和DISABLE两个日期文本框。
所以请帮助我,
这是我的代码。此外,我为radiobuttonlist提供了AutoPostBack = true。
Dear Friends,
am working on Asp.net, c#, SqlServer 2005.
I have Two Textboxes FromDate and ToDate and I have two Dropdwonlist lists with Month & Year.
I have Radiobuttonlist on my webpage, In this i have two items with Enable option.
When I select one option enable, it should ENABLE two dates textboxes and DISABLE two dropdownlists.
and When I select 2nd option enable, it should ENABLE two dropdownlist and DISABLE two dates textboxes.
so please help me,
This is my code. and Also i gave AutoPostBack = true for radiobuttonlist.
protected void RBLoginHistorySelection_SelectedIndexChanged(object sender, EventArgs e)
{
if (RBLoginHistorySelection.SelectedItem.Selected == true)
{
TxtFromDate.Enabled = true;
TxtToDate.Enabled = true;
DDLMonth.Enabled = false;
DDLYear.Enabled = false;
}
else
{
TxtFromDate.Enabled = false;
TxtToDate.Enabled = false;
DDLMonth.Enabled = true;
DDLYear.Enabled = true;
}
}
请帮忙,在此先感谢。
Please help, Thanks in Advance.
试试这段代码:
Try this code:
<asp:radiobuttonlist id="RadioButtonList1" runat="server" autopostback="true" xmlns:asp="#unknown">
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:listitem text="Enable Text"></asp:listitem>
<asp:listitem text="Enable DDL"></asp:listitem>
</asp:radiobuttonlist>
<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:dropdownlist id="DropDownList1" runat="server" xmlns:asp="#unknown"></asp:dropdownlist>
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedItem.Text == "Enable Text") // Enable text box
{
TextBox1.Enabled = true; // this is a just an example, place your controls here.
DropDownList1.Enabled = false;
}
else if (RadioButtonList1.SelectedItem.Text == "Enable DDL") // Enable Dropdown
{
TextBox1.Enabled = false;
DropDownList1.Enabled = true;
}
else
{
TextBox1.Enabled = false;
DropDownList1.Enabled = false;
}
}