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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top