I have a dropdownlist
in aspx called ddlService
.
I want to added the listitems from behind.
When I add, I will create them in order of Title and items underneath like..
Title1
Item1
Item2
Title2
Item1
Item2
Titles should not be able to click. Only Items should be able to click.
ListItem tempServicesItem = new ListItem();
tempServicesItem.Text = tempTitle;
tempServicesItem.Value = tempTitle;
tempServicesItem.Enabled = false;
ddlServices.Items.Add(tempServicesItem);
tempServicesItem = new ListItem();
tempServicesItem.Text = tempItem;
tempServicesItem.Value = tempItem;
ddlServices.Items.Add(tempServicesItem);
The problem I encountered is The ListItems
with (Enabled=false
) are not appearing in aspx.
When I change it to (Enabled=true
), it is appearing.
I must have missed out something. Can anyone point out?
Thanks.
I believe this is what you're looking for. (Not tested)
tempServicesItem.Attributes.Add("disabled", "disabled");
MSDN documentation says
You cannot use this property to disable a ListItem control in a DropDownList control or ListBox control.
I think you need to set the "disabled" attribute which corresponds to the HTML markup for the option element
tempServicesItem.Attributes["disabled"] = "true";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With