?
Solved

Get the prevoius selected item for the ListBox in SelectedIndexChanged function

Posted on 2008-11-15
13
Medium Priority
?
585 Views
Last Modified: 2012-08-13
Hi, Is it possible to get the selected prevoius selected(the one before the current one) item for the ListBox in SelectedIndexChanged function?
0
Comment
Question by:Abdu_Allah
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 800 total points
ID: 22966437
Store that on a session and you can know it
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22966452
It will be change also once the the user select anothe item.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22966461
>> It will be change also once the the user select anothe item.
Why ?
When you click on a item you store that value(index) on a session. After you do all your work, you copy to another one (the previous selected item).
This way you will have the actual and the old one.
<!-- richText -->
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22966536
Can you explain your idea with code please? because whenever you copy it the prevoius one will deleted!
 
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22966600

In the SelectedIndexChanged event you can do:

Session("old") = Session("new")
Session("new") = Me.ListBox1.SelectedIndex ' or you can use a value
 
This way you store the previous value (or in this case index) of the listbox and the new one.
 

PS: Don't forget to set the AutoPostBack in the listbox to true
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22966602
I want the old selected Item in SelectedIndexChanged function.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22966632
Don't understand!
You just have to change:
Session("new") = Me.ListBox1.SelectedIndex
with
Session("new") = Me.ListBox1.SelectedItem.Text
 
Or do I understood it wrong ?
 
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22967144
>Or do I understood it wrong ?
Exactly.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22967460
>> Exactly
Can you explain ?
0
 
LVL 8

Assisted Solution

by:tiagosalgado
tiagosalgado earned 400 total points
ID: 22969329
1. Add a ASP.NET Hidden Field to store your old value.
2. Add this line to Page_Load ListBox1.Attributes.Add("onfocus", String.Format("{0}.setAttribute('value',this.value)", hidden.ClientID));

Access to hidden field value and get your previous selected item.
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22970083
But by this way you cannot get the old value if you select a new one!
0
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22971655
Yes you can. You're storing to hidden field the value selected when your listbox get focus. When you click to another one, if you get the hidden field value you get the previous item value.
0
 
LVL 3

Assisted Solution

by:Rupesh P
Rupesh P earned 800 total points
ID: 22973695
Add a hidden field in the page.

protected void DropDownList1_SelectedIndexChanged(object sender,
                  EventArgs e)
        {
             //current value
             int current = DropDownList1.SelectedIndex;
             int oldValue = hiddenField1.value;
             hiddenField1.value = current;
        }

now you have the previously selected value in the oldValue variable.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question