Search code examples
asp.netlistviewdata-bindingdataitem

Items of a ListView have DropDownList: How to get the DataItem when selection changes?


So I have something like this:

My ListView setup

Under the "Products" ComboBox there is a ListView that displays the new items that are added when the user clicks the "Add" button to add the selected product.

When the user makes a Product Descriptor selection for a product, I need to change a property of the associated data bound object. How do I access that object? I have a handler for the SelectedIndexChanged event of a given Product Descriptor ComboBox, but how do I get the DataItem of the row containing the ComboBox that had its selection changed?

I thought about ListView's ItemCommand event, but I can't see how I would use it in this case.

I also saw this post, in which one answer mentions storing ids in hiddenfields: DropDownList inside Repeater: How to handle SelectedIndexChange and get DataItem?

But in that case, how would I get the Ids from those hidden fields?

Thanks for your help!


Solution

  • Tim Schmelter's answer led me to this answer:

                Dim comboBox = CType(sender, RadComboBox)
                Dim item = CType(comboBox.NamingContainer, ListViewItem)
                Dim myListItem = myCollection(item.DataItemIndex)