DropDownList in ASP.Net

DropDownList in ASP.Net

Previous Home Next

 

A drop down list is one of the most important kinds of web form inputs. It lets users select among customized choices. Drop down lists are found in almost all web forms on the Internet and commonly used in application forms and online surveys.

The DropDownList control raises (an event the SelectedIndexChanged event) when users select an item. By default, this event does not cause the page to be posted to the server, but you can cause the control to force an immediate post by setting the AutoPostBack property to true.

 

Design Code:

<
asp:DropDownList ID="DropDownList1" runat="server" Height="47px" Width="73px">
</
asp:DropDownList
>


 .CS Code:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DropDownList1.Items.Add("pototo");
            DropDownList1.Items.Add("Tamato");
            DropDownList1.Items.Add("brinjal");
            DropDownList1.Items.Add("Lime");
            DropDownList1.Items.Add("Pea");


            ///////////////////////////////////////////////
            DropDownList2.Items.Add("Jeans");
            DropDownList2.Items.Add("Shirt");
            DropDownList2.Items.Add("Cap");
            DropDownList2.Items.Add("Blaser");
            DropDownList2.Items.Add("Tie");
            //////////////////////////////////////////////////

            DropDownList3.Items.Add("Lather");
            DropDownList3.Items.Add("Canvas");
            DropDownList3.Items.Add("Sports");
            DropDownList3.Items.Add("Sandle");
            DropDownList3.Items.Add("Sleeper");

            /////////////////////////////////////////////
            DropDownList4.Items.Add("Fan");
            DropDownList4.Items.Add("TybeLight");
            DropDownList4.Items.Add("Plug");
            DropDownList4.Items.Add("Holder");
            DropDownList4.Items.Add("Wire");
        }

   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
      ListBox1.Items.Add("Vegitables:" + DropDownList1.SelectedItem.Text);
      
      //DropDownList1.Items.Clear();
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
       
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListBox1.Items.Add("Cloths:" + DropDownList2.SelectedItem.Text);
      

    }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListBox1.Items.Add("Showes:" + DropDownList3.SelectedItem.Text);
      
    }
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListBox1.Items.Add("Electronics:" + DropDownList4.SelectedItem.Text);
      
    }
Output

Previous Home Next