How to make dropdownlist listitems invisible

I have two related controls DropDownList. Depending on the choice in the parent DropDownList, I want to hide some elements of the child element DropDownListif they were not associated with the selected element in the parent DropDownList.

I tried to do something like this:

foreach(ListItem item in ddlChildren.Items)
{
     item.Visible = /* some logic here */
}

However, the property Visibledoes not seem to be available here.

Can someone please suggest how I will achieve this functionality?

+3
source share
4 answers

You cannot “hide” the values. You need to reassign or replenish your list from scratch.

, , , , .

+1

- , Enabled , , false. false, .

+1

-. , , enable , . , Windows. . , VB. # . - .

this.ddlYourDropDown.Items(3).Enabled == false;

, ...

this.ddlYourDropDown.Items.FindByValue ("YourItemValue"). Enabled == false

+1
source

For such a scenario, I usually use the cascading drop-down expander from AjaxControlToolkit.

Have a look here: http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

Project Homepage: http://ajaxcontroltoolkit.codeplex.com/

Note that this approach does not change the visibility of list items, but dynamically populates list items based on the results of the web service method.

0
source

All Articles