Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2006, 12:02 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session State Problem?

Hi,

     I have 2 listbox controls. I am using Session variable to retain focus on the last selected item of listbox1. I am doing some LINK and UNLINK operation with the 2 listboxes. All is working fine but when i work on the last element of the listbox1, it gives the following error:
Specified argument was out of the range of valid values. Parameter name: value .

I have checked by Debugging that the Session variable set is getting passed to the calling listbox1:

listbox1.SelectedIndex = CInt(Session("SVar"))

but it still gives the above mentioned error & ONLY FOR THE LAST SELECTED element in the listbox1.

will someone suggest for the missing link?

Regards
Monica

 
Old August 17th, 2006, 12:27 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I dont understand what you mean by: "All is working fine but when i work on the last element..."

Some things to consider:

1. When you dynamically add items to a listbox for example:

    foreach(DataRow dr in dt.Rows()){
    lb.Items.Add(New ListItem(dr[text], dr[value]));
    }
    in your case it means that the value you are trying to pull from the datarow and insert as the value of the item doesnt exist, you have broken the bounds of the array.

2. You are setting the SelectedIndex based on a variable, remember that index's for dropdownlists and listboxes are 0 based, it could be that the value of your session variable excceds the number of elements in the list.

If you cannot resolve the issue, post the code that is problematic.



"The one language all programmers understand is profanity."
 
Old August 17th, 2006, 01:36 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

    I am doing LINK & UNLINK operation in the 2 listboxes.If i select an element in listbox1 & another element in listbox2, i am performing LINK/UNLINK operation. Also, I need to keep the selected item in Listbox1 highlighted. "All is working fine but wheni work on the last element..... means i am able to do the LINK/UNLINK operation on all elements on listbox1 & the selected item remains highlighted while i switch to some other link page & come back. BUT when i UNLINK the last element in listbox1, i get the ERROR( i showed u last time) & here is the code:

        Dim tbl As New DataTable
        listbox1.DataSource = tbl
        listbox1.DataTextField = "Name"
        listbox1.DataValueField = "NameID"
        listbox1.DataBind()

        If Not (Session("SVar")) Is Nothing Then
            If listbox1.Items.Count <> 0 Then
              listbox1.SelectedIndex = Session("SVar")
            End If
        End If

I am collecting the Session Variable here:

Private Sub listbox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox1.SelectedIndexChanged

        If listbox1.SelectedIndex > -1 Then
            Session("SVar") = listbox1.SelectedIndex
        End If
    End Sub

I have checked while debugging that listbox1 index value collected in SVar here is reaching to the code given earlier. BUT when i UNLINK the last element in the listbox1, i am THROWN OUT....by the error, i told u earlier.

Regards
Monica


 
Old August 17th, 2006, 01:39 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, i am getting error in this line of code:

listbox1.SelectedIndex = Session("SVar")

Specified argument was out of the range of valid values. Parameter name: value .



 
Old August 17th, 2006, 01:46 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I do not understand what you mean by LINK/UNLINK.

If I can guess correctly though, the error is coming from your If statement, it is not enough to just check that the listbox <> 0 because, for example, if your session value is 2 and the item count is 1, that will throw an error.

If Not (Session("SVar")) Is Nothing Then
        If (CINT(Session("SVar")) <= (listbox.Items.Count - 1) then listbox1.SelectedIndex = Session("SVar")
End If


"The one language all programmers understand is profanity."
 
Old August 17th, 2006, 02:06 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey,
     It is working, i mean i can do the UNLINK operation for the last element in listbox1 BUT i am loosing the Session Variable FOCUS on the last selected element of listbox1. But this is again happening on the LAST element of the list.

Regards

 
Old August 17th, 2006, 02:11 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, i didnt see your first line.By LINK i am showing the element selected in the listbox2 under the selected element in listbox1 & VICE VERSA.

 
Old August 17th, 2006, 02:48 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

ListBox1 ListBox2
-------- --------
   5 X 1
   4 2
   3 3
   2 4
   1 5 X

Consider the above. So what you are saying that if in ListBox 1 if '5' is selected then in ListBox 2 5 would also be selected and then if 5 is unselected from ListBox 1 it is also unlinked from listbox 2?

"The one language all programmers understand is profanity."
 
Old August 17th, 2006, 03:08 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

LIST1 LIST2
_____ ______

Anna Tennis

Boris *LINK BUTTON* Hockey

Kaka *UNLINK BUTTON* Football

SACHIN Cricket

Now if I select Boris from LIST1 & Tennis from LIST2 & then click *LINK BUTTON*, LIST1 & LIST2 becomes like this:

LIST1 LIST2
_____ ______

Anna Tennis
                                            -Boris
Boris *LINK BUTTON* Hockey
-Tennis
Kaka *UNLINK BUTTON* Football

SACHIN Cricket

Selecting -Tennis from LIST1 & -Boris from LIST2 & selecting the *UNLINK BUTTON* will again create the list pair as given initially.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Session State|View State|Do I have other options? rockon ASP.NET 1.x and 2.0 Application Design 2 October 5th, 2005 07:10 PM
maintaining session state in C# grs General .NET 0 January 13th, 2005 03:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.