Adding a String in ASP.NET in a ListBox

I need a string added to a list in ASP.NET in order to provide some separation into many parameters that the user can select. Currently, we have more than 20 different options for the user to select, and I need to put the most popular top. I have logic that puts a popular option on top, but I think that a line in the list will help the user to separate them from the rest of the list. List items are populated in code.

+4
source share
2 answers

You can use the optgroup tag to separate.

<select> <option value="XX"/> <optgroup label="separation"/> <option value="BB"/> </select> 

To give only a string, you will need to cheat a little. See below

 <style type="text/css"> optgroup {border-bottom:solid thin black; width:100%;} </style> <select> <option value="XX"/> <optgroup label=" "/> <option value="BB"/> </select> 

If your data is already loaded, you can run some jquery after.

 $('select option[value="XX"]').after('<optgroup label=""/>'); 
+3
source

There is no way to create groups of options from DropDownLists and Listboxes in asp.net.

Found those articles that provide a server and client solution to achieve what you are looking for:

Optgroup in .NET Listbox

Dropdownlist control with <optgroup> s for asp.net (web forms)?

+1
source

Source: https://habr.com/ru/post/1384773/


All Articles