Reputation: 641
My overall goal is to be able to have a drop down list, and when a value is selected in the drop down list I will be able to select specific values to that option in drop down list 2 and so on. Eventually displaying unique results in Grid View.
For Example,
DropDown List 1
Cars
Food
Colors <- Selected Value
DropDown List 2
Red
Blue <- Selected Value
Black
Grid View Results
Specific Colors Number Available
Baby Blue 2
Night Blue 5
Sky Blue 0
Dark Blue 3
Upvotes: 0
Views: 1164
Reputation: 66
If I'm understanding what you want to do correctly, you could set the initial value to in DropDownList1 to none, and then create an event to handle the SelectedIndexChanged event for DropDownList1, which could switch based on the index selected. For example:
<asp:DropDownList runat="server" ID="DropDownList1" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged"> put all your list items </asp>
An then in your code behind file:
protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
{
List<string> elements; // a List containing the elements you want in the second drop own menu (you will need one for each possible set of elements)
switch(DropDownList1.SelectedValue)
{
case "Colors":
DropDownList2.Items.Clear();
DropdownList2.Items.Add(elements);
break;
// And then your other cases here
}
}
And then do a similar function call when an index is selected on DropDownList2 to set your gridview.
Upvotes: 1
Reputation: 1005
If I understand you correctly, you want to have a first dropdown to choose a category and then a second one to choose a value within that category. If your data is bound then a good way to do this would be to have a converter on the ItemSource of the second dropdown. That converter will take a property that the first dropdown sets and use that to decide which options to show. You will have something like this:
ComboBox1 -> Category
Category -> value list -> ComboBox2
I don't have any of your code to reference or give you examples for but here is a pretty good tutorial on something similar: http://sekagra.com/wp/2013/04/dynamic-itemssource-for-combobox-in-a-datagrid/
Upvotes: 0