How can I find the ItemIndex in a ListView?

Discussion in 'ASP .Net' started by aleko, Mar 19, 2008.

  1. aleko

    aleko Guest

    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
     
    aleko, Mar 19, 2008
    #1
    1. Advertising

  2. On Mar 19, 7:20 pm, aleko <> wrote:
    > 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
     
    Alexey Smirnov, Mar 19, 2008
    #2
    1. Advertising

  3. aleko

    aleko Guest

    On Mar 19, 1:41 pm, Alexey Smirnov <> wrote:
    > On Mar 19, 7:20 pm, aleko <> wrote:
    >
    > > 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/li...dn2.microsoft.com/en-us/library/bb398790.aspx


    Ah, it's called DisplayIndex. Thanks very much!

    -Aleko
     
    aleko, Mar 22, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephan

    e.Item.ItemIndex returns wrong value

    Stephan, Jul 26, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    3,477
    Stephan Bussing
    Jul 26, 2004
  2. brian yeo via .NET 247

    read row (1 field) from ItemIndex

    brian yeo via .NET 247, Mar 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    726
    brian yeo via .NET 247
    Mar 7, 2005
  3. Rod
    Replies:
    2
    Views:
    871
  4. shapper
    Replies:
    2
    Views:
    353
    Teemu Keiski
    Nov 18, 2007
  5. .
    Replies:
    0
    Views:
    745
Loading...

Share This Page