How can I find the ItemIndex in a ListView?

  • Thread starter Thread starter aleko
  • Start date Start date
A

aleko

Hi,

I was in the middle of converting some old Repeater code to use a
ListView, when I discovered that the ListViewItem class doesn't have
an ItemIndex property. Is there another way of getting the index of
the current list item?

Thanks,

Aleko
 
Hi,

I was in the middle of converting some old Repeater code to use a
ListView, when I discovered that the ListViewItem class doesn't have
an ItemIndex property. Is there another way of getting the index of
the current list item?

Thanks,

Aleko

When ListView is clicked the ItemCommand() event is raised and a
ListViewCommandEventArgs object is passed, which can be used to
retrieve control values such as an index of the current row.

protected void ListView1_ItemCommand(object sender,
ListViewCommandEventArgs e)
{
... (ListViewDataItem)e.Item.DisplayIndex

See more:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewcommandeventargs.aspx
http://msdn2.microsoft.com/en-us/library/bb398790.aspx
 
Back
Top