There are two dropDownLists on my form. In one DropDownList items
are-
1)BE
2)Drawing
3)PG

I want if a user selects BE in dropdownlist3 then in dropDownlist4 items are
IT, CSE, MECH


I want if a user selects Drawing in dropdownlist3 then in dropDownlist4 items are
Drawing1, Drawing2


I want if a user selects PG in dropdownlist3 then in dropDownlist4 items are
MBA, MSC, MCA

I do the foll. coding,but errors are there--
Check it out--

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
DropDownList3.Items.Add("BE");
DropDownList3.Items.Add("Drawing");
DropDownList3.Items.Add("PG");
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList3.SelectedItem =="BE")
{
DropDownList4.Items.Clear();
DropDownList4.Items.Add("IT");
DropDownList4.Items.Add("CSE");
DropDownList4.Items.Add("MECH");
}
else if (DropDownList3.SelectedItem =="Drawing")
{
DropDownList4.Items.Clear();
DropDownList4.Items.Add("Drawing 1");
DropDownList4.Items.Add("Drawing 2");
}
else
{
DropDownList4.Items.Clear();
DropDownList4.Items.Add("MBA");
DropDownList4.Items.Add("MSC");
DropDownList4.Items.Add("MCA");

}
}
}

Recommended Answers

All 5 Replies

What's your error? I'm guessing it is because you are comparing a listitem to a string. Instead of .SelectedItem try .SelectedItem.Text or .SelectedValue.

If I m using the Selected Item errore are there,if instead of item I use Selected Value,no errors are there,but when i select in any item in Dropdownlist3, in dropdownlist4 no item is displayed....

Hi Mansi,

write the statement to display the dropdown.

try this in the Load event, it should solve your problem:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) 
{
DropDownList1.Items.Clear();
DropDownList3.Items.Add("BE");
DropDownList3.Items.Add("Drawing");
DropDownList3.Items.Add("PG");
}
}

Regards
Sunil Punjabi
<URL Snipped>

Drop down list to choose type of :Reader NFC/RFID reader
when user choose reader show description
Description for RFID Reader : Reading range 6-12 Meteres.
Description for NFC Reader : Reading Range 3-5 mm.
can you tell me source code using asp.net

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.