We help IT Professionals succeed at work.

How to get the row index of a listview

philwill4u
philwill4u asked
on
In asp.net 3.5 code I have a combobox inside a listview.  The combo triggers the SelectedIndexChanged event.

How do I get the row index of the ListView that the combo belongs to from within the SelectedIndexChanged?

Thanks
phil
Comment
Watch Question

try its parent property

parent property gives you its parent control in which it is placed.

you may need to use parent.parent

hope this helps you.
Top Expert 2009

Commented:

Author

Commented:
Thanks... can you give me an example.  Assuming cbo is the combo and ListView1 is the listview and we're in the cbo_SelectedIndexChange event.
Top Expert 2009

Commented:
My bad, I assumed the question to be something else. Here are the actual links that'll help you getting the row index.

http://forums.asp.net/t/1329009.aspx
http://forums.asp.net/t/1197494.aspx

Arun

Author

Commented:
I managed to fix the issue with the following code...

            ASPxRoundPanel currRoundPnl2 = (ASPxRoundPanel)cbo.NamingContainer;
            ListViewItem currItem = (ListViewItem)currRoundPnl2.NamingContainer;
            int rowIndex = currItem.DataItemIndex;

The aspxRoundPanel is a DevExpress control.  I had to go back up the namingcontainer tree and grab the index of the listviewitem.

Top Expert 2009

Commented:
Good to know things worked out for you. Please select a post (any appropriate post) as the solution and mark this question as PAQ.

Arun