0

I am trying to integrate an adapter to get support for the OptGroup tag in .net. i took the same adapter as i usually did (been a while, but no build errors or warnings). I set attributes when i add items into the DropDownList, and attempt to read them in the adapter and they seem to be set to Nothing. I entered breakpoints at points of interest and after being set, i can see the Attributes having a value. And in the adapter, the item remains but without said attribute.

To get every possible glitch out of the way i went into full hardcode for adding items, and here we have the result. The display does not group up, as the !=nothing never is met on the adapter.

declaration of list:

Dim item1 As New ListItem("potatoes", "1")
item1.Attributes("OptionGroup") = "optionGroup1"

Dim item2 As New ListItem("Onions", "2")
item2.Attributes("OptionGroup") = "optionGroup2" 'here the optiongroup is set, and debugger sees value to it.

Me.cboMaterial.Items.Add(item1)
Me.cboMaterial.Items.Add(item2)

where it fails in the adapter:

 Dim list As DropDownList = Me.Control
 Dim currentOptionGroup As String = ""
 Dim renderedOptionGroups As New Collection



 For Each item As ListItem In list.Items
     If item.Attributes("OptionGroup") = "" Then 'here, the item is worth something (potatoes) but the OptionGroup is nothing.
         RenderListItem(item, writer)
     Else
         If currentOptionGroup <> item.Attributes("OptionGroup") Then
             If currentOptionGroup <> "" Then
                 RenderOptionGroupEndTag(writer)
             End If
             currentOptionGroup = item.Attributes("OptionGroup")
             RenderOptionGroupBeginTag(currentOptionGroup, writer)
         End If
         RenderListItem(item, writer)
     End If
Next

i must be missing something, perhaps trivial, but I've been looking at the same thing for too long. any help would be welcome.

edit: i have tried adding the attribute with secondary syntax... by desperation i guess.

item2.Attributes.Add("OptionGroup","optionGroup2")

it changes nothing :P

  • Possible duplicate of [How can I add option groups in ASP.NET drop down list?](https://stackoverflow.com/questions/16167862/how-can-i-add-option-groups-in-asp-net-drop-down-list) – wazz Dec 19 '17 at 01:26
  • the accepted answer links to the thread where i got the original class a while back... which is pretty much how i feel this search been going. dont worry i am not an abusive asker, i do not ask after 1h of research. i tried this for over 16 hours and cannot seem to have the OptionGroup attribute follow into the adapter. it just doesnt. it's there before, it's there all along page load, i enter the actual adapter code, and the item loop just does not have any attributes for the items. key->value only. – Ralph Thomas Hopper Dec 19 '17 at 13:00

0 Answers0