user1677110
user1677110

Reputation: 11

How dynamically dropdown list values changes by selecting another dropdown

I have two dropdown lists. One is weekday, another is type of food. In page load i am getting weekdays values list in weekday dropdown list.

Now the problem is by selecting values in weekday dropdown, the corresponding values have for food have to be fetched from the database.

example: Suppose if I select monday in weekday dropdown list, the second dropdown needs to display what are the items present in the monday day .

datatabase is already designed.

Upvotes: 1

Views: 1915

Answers (2)

NoviceProgrammer
NoviceProgrammer

Reputation: 3365

In selection change event of the first drop down, get the details of the second drop down from the database and bind it. To fire the selection changed event whenever user selects a new item, set AutoPostback=true for the drop down list.

If you want to use Ajax; you can take a look at the Cascading Drop Down Extender

Here you should not set the AutoPostback=true as the extender will take care of it.

Upvotes: 4

user1366148
user1366148

Reputation:

You can use selection change event of your weekday combobox. Inside that event fetch the data according to current selected item and then set the result to the food combobox.

List outputfoodList;

//Retrive foods and assing result to list ... ... ...

for(string food in outputfoodList) { foodCmb.Items.Add(food); }

Upvotes: 1

Related Questions