Skip to content

Displaying only related values in box 2 based on option selecting in box1 in ASP.Net

Aditya Varma Mudunuri

Asked Mar 1, 2012, 2:16 AM EST1 answer
Share
LinkedInX
Here i am having 2 dropdown lists in which an item displayed in List1 should display the appropriate options in list 2 likeways If I select TV in Dropdown List 1 then it should display TV.ON,TV.MUTE & TV.OFF only in Dropdown List 2.


Please Find a solution for this issue

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Senthilkumar
    0
    Hi,

    Consider you have the dropdowns

    1. Dropdown1
    2. Dropdown2

    Load the first drop down values in the page load.

    Dropdown1.DataSource = DataSet1.Tables[0];
    Dropdown1.DataTextField = "Name";
    Dropdown1.DataValueField = "ID"; 
    Dropdown1.DataBind();

    Enable the autopostback property for the first dropdown; and write the index changed event.

    protected void  Dropdown1_OnInexchanged(object sender, EventArgs e)
    {
            int _Id =  Convert.ToInt32(Dropdown1.SelectedItem.Value.ToString());
            //Load the data based on the ID and get some datatable/DataSet/Collection
             Dropdown2.DataSource = DataSet2.Tables[0];
            Dropdown2.DataTextField = "Name1";
            Dropdown2.DataValueField = "ID1"; 
            Dropdown2.DataBind(); 
    }

    You can use the AJAX update panel to reload the page again when select in the first drop down.
    0