1

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!

Community
  • 1
  • 1
unnknown
  • 1,715
  • 2
  • 19
  • 37
  • I just realized that the question I referenced probably has what I need in the accepted answer. Will check it out – unnknown Oct 30 '12 at 22:16

2 Answers2

1

You just have to cast the NamingContainer of the DropDownList:

var ddl      = (DropDownList) sender;
var item     = (ListViewItem) ddl.NamingContainer;
var rowView  = (DataRowView)  item.DataItem;
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Thanks much. This this lead me to the right answer. DataItem is Null in my case, so I ended up using item.DataItemIndex to index into the collection I bind to – unnknown Nov 15 '12 at 19:01
0

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)
unnknown
  • 1,715
  • 2
  • 19
  • 37