DropDownList Program in ASP.Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mansi sharma
    New Member
    • Mar 2008
    • 22

    DropDownList Program in ASP.Net

    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.P age
    {
    protected void Page_Load(objec t sender, EventArgs e)
    {
    DropDownList3.I tems.Clear();
    DropDownList3.I tems.Add("BE");
    DropDownList3.I tems.Add("Drawi ng");
    DropDownList3.I tems.Add("PG");
    }
    protected void DropDownList3_S electedIndexCha nged(object sender, EventArgs e)
    {
    if (DropDownList3. SelectedItem ="BE")
    {
    DropDownList4.I tems.Clear();
    DropDownList4.I tems.Add("IT");
    DropDownList4.I tems.Add("CSE") ;
    DropDownList4.I tems.Add("MECH" );
    }
    else if (DropDownList3. SelectedItem ="Drawing")
    {
    DropDownList4.I tems.Clear();
    DropDownList4.I tems.Add("Drawi ng 1");
    DropDownList4.I tems.Add("Drawi ng 2");
    }
    else
    {
    DropDownList4.I tems.Clear();
    DropDownList4.I tems.Add("MBA") ;
    DropDownList4.I tems.Add("MSC") ;
    DropDownList4.I tems.Add("MCA") ;

    }
    }
    }

    But Its not working.
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    What error are you getting back from your application?

    Nathan

    Comment

    • mansi sharma
      New Member
      • Mar 2008
      • 22

      #3
      Error Operator '==' cannot be applied to operands of type 'System.Web.UI. WebControls.Lis tItem'

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        Originally posted by mansi sharma
        Error Operator '==' cannot be applied to operands of type 'System.Web.UI. WebControls.Lis tItem'
        Your conditional statements (if and else if) must compare using the == operator.

        Code:
         if(dropdown1.SelectedValue == "BE") 
        {
        //do something
        }
        Nathan

        Comment

        Working...