Need to Disable Dropdown Box ASP.NET C# 2.0

I need to be able to disable multiple dropdowns when either dropdown has a value first.  This is for a reporting screen.  Example - if a user selects state, city and country needs to be disable
jedwards_2Asked:
Who is Participating?
 
Anurag ThakurConnect With a Mentor Technical ManagerCommented:
i am assuming that the data in the drop down list has been bound in the page load event
there is a "Select" option in all the drop downs  and the value is -1
<asp:DropDownList ID="ddStates" runat="server" OnSelectedIndexChanged="ddStates_SelectedIndexChanged" AutoPostBack="True" Width="150px"></asp:DropDownList>
<asp:DropDownList ID="ddCounties" runat="server" Width="150px" OnSelectedIndexChanged="ddCounties_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
 
 
C# code
	protected void ddStates_SelectedIndexChanged (object sender, EventArgs e)
	{
		if (ddStates.SelectedValue != "-1")
		{
			ddCountries.Enabled = false;
		}
		else
		{
			ddCountries.Enabled = true;
		}
	}
 
	protected void ddCounties_SelectedIndexChanged (object sender, EventArgs e)
	{
		if (ddCountries.SelectedValue != "-1")
		{
			ddStates.Enabled = false;
		}
		else
		{
			ddStates.Enabled = true;
		}
	}

Open in new window

0
 
Anurag ThakurTechnical ManagerCommented:
set the autopostback event for all the dropdowns
set the OnSelectedIndexChanged changed property for each dropdown and in that function for the event check if a value eg for state is set then disable the other 2 dropdowns and vice versa
0
 
jedwards_2Author Commented:
i thought i did that.  can you provide any examples?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.