selectedindexchanged

M

mkiger

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?
 
P

Phillip Williams

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
 
P

Phillip Williams

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

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

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top