selectedindexchanged

Discussion in 'ASP .Net Web Controls' started by mkiger, Oct 20, 2005.

  1. mkiger

    mkiger Guest

    Hey guys,
    When I use the selectedindexchanged event of a listbox web control I would
    like to be able to to reference the previously selected item. Is there a way
    to do that?
     
    mkiger, Oct 20, 2005
    #1
    1. Advertising

  2. Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    Dim prevSelectedIndex As Integer = 0
    'check if the ViewState("prevSelectedIndex") exists
    If ViewState("prevSelectedIndex") Is Nothing Then prevSelectedIndex
    = CType(ViewState("prevSelectedIndex"), Integer)
    'do here the processing of your listbox_SelectedIndexChanged event
    '...
    'Save the selected index in the ViewState
    ViewState("prevSelectedIndex") = CType(sender, ListBox).SelectedIndex

    End Sub
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "mkiger" wrote:

    > Hey guys,
    > When I use the selectedindexchanged event of a listbox web control I would
    > like to be able to to reference the previously selected item. Is there a way
    > to do that?
     
    Phillip Williams, Oct 20, 2005
    #2
    1. Advertising

  3. A correction for the condition; it should read like this:
    If Not ViewState("prevSelectedIndex") Is Nothing Then prevSelectedIndex
    = CType(ViewState("prevSelectedIndex"), Integer)

    "Phillip Williams" wrote:

    > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > Dim prevSelectedIndex As Integer = 0
    > 'check if the ViewState("prevSelectedIndex") exists
    > If ViewState("prevSelectedIndex") Is Nothing Then prevSelectedIndex
    > = CType(ViewState("prevSelectedIndex"), Integer)
    > 'do here the processing of your listbox_SelectedIndexChanged event
    > '...
    > 'Save the selected index in the ViewState
    > ViewState("prevSelectedIndex") = CType(sender, ListBox).SelectedIndex
    >
    > End Sub
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "mkiger" wrote:
    >
    > > Hey guys,
    > > When I use the selectedindexchanged event of a listbox web control I would
    > > like to be able to to reference the previously selected item. Is there a way
    > > to do that?
     
    Phillip Williams, Oct 20, 2005
    #3
  4. mkiger

    mkiger Guest

    Thank you very much! The only thing that bothers me is why I didn't think of
    this.

    "Phillip Williams" wrote:

    > A correction for the condition; it should read like this:
    > If Not ViewState("prevSelectedIndex") Is Nothing Then prevSelectedIndex
    > = CType(ViewState("prevSelectedIndex"), Integer)
    >
    > "Phillip Williams" wrote:
    >
    > > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > > Dim prevSelectedIndex As Integer = 0
    > > 'check if the ViewState("prevSelectedIndex") exists
    > > If ViewState("prevSelectedIndex") Is Nothing Then prevSelectedIndex
    > > = CType(ViewState("prevSelectedIndex"), Integer)
    > > 'do here the processing of your listbox_SelectedIndexChanged event
    > > '...
    > > 'Save the selected index in the ViewState
    > > ViewState("prevSelectedIndex") = CType(sender, ListBox).SelectedIndex
    > >
    > > End Sub
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "mkiger" wrote:
    > >
    > > > Hey guys,
    > > > When I use the selectedindexchanged event of a listbox web control I would
    > > > like to be able to to reference the previously selected item. Is there a way
    > > > to do that?
     
    mkiger, Oct 20, 2005
    #4
    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. Dominic
    Replies:
    2
    Views:
    738
    Saravana
    Jul 4, 2003
  2. Robert Hanson
    Replies:
    0
    Views:
    550
    Robert Hanson
    Jul 10, 2003
  3. Robert Hanson
    Replies:
    0
    Views:
    487
    Robert Hanson
    Jul 10, 2003
  4. Pepito Grillo

    SelectedIndexChanged event in DropDownList

    Pepito Grillo, Jul 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    448
    Pepito Grillo
    Jul 28, 2003
  5. Kevin Spencer

    Re: SelectedIndexChanged event not firing

    Kevin Spencer, Aug 1, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    712
    Joe Bleaux
    Aug 2, 2003
Loading...

Share This Page