473,378 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Listbox populate with session value

Iam fairly new to .net programming. I have a listbox with multi-select
option. If page not postback, i do the data binding. On selection of values,
i save it in a session varible as this is used my couple of other pages. When
i traverse from the main page(where list box is created) to the sub pages and
come back , the value is lost and i do not have selected in the list box. Can
anyone please tell me what iam missing. I still have the values in the
session variable.
thanks in advance.
Jun 5 '07 #1
7 2865
On Jun 5, 7:27 pm, Smita <S...@discussions.microsoft.comwrote:
Iam fairly new to .net programming. I have a listbox with multi-select
option. If page not postback, i do the data binding. On selection of values,
i save it in a session varible as this is used my couple of other pages. When
i traverse from the main page(where list box is created) to the sub pages and
come back , the value is lost and i do not have selected in the list box. Can
anyone please tell me what iam missing. I still have the values in the
session variable.
thanks in advance.
You should select the value of the list again.

ListBox.Items.FindByValue(Session["MyListValue"].ToString()).Selected
= true;

Jun 5 '07 #2
When you say come back - do you mean use the back button?
Jun 6 '07 #3
Selection will be maintained only within the same page postback (of course,
view state should have been enabled) not across page navigations.

"Smita" wrote:
Iam fairly new to .net programming. I have a listbox with multi-select
option. If page not postback, i do the data binding. On selection of values,
i save it in a session varible as this is used my couple of other pages. When
i traverse from the main page(where list box is created) to the sub pages and
come back , the value is lost and i do not have selected in the list box. Can
anyone please tell me what iam missing. I still have the values in the
session variable.
thanks in advance.
Jun 6 '07 #4
On Jun 6, 11:11 am, Siva M <shiva...@online.excite.comwrote:
Selection will be maintained only within the same page postback (of course,
view state should have been enabled) not across page navigations.
He used a Session object, not a ViewState.

Jun 6 '07 #5
The Selected value is only available from ViewState on the same page. You are
navigating to different pages and then coming back.

You need to store the selected value index in session also, and restore it
say, in your Page_Load handler.
Peter

Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Smita" wrote:
Iam fairly new to .net programming. I have a listbox with multi-select
option. If page not postback, i do the data binding. On selection of values,
i save it in a session varible as this is used my couple of other pages. When
i traverse from the main page(where list box is created) to the sub pages and
come back , the value is lost and i do not have selected in the list box. Can
anyone please tell me what iam missing. I still have the values in the
session variable.
thanks in advance.
Jun 6 '07 #6
Smita,
Try enabling view state for the listbox control. This will maintain your
values, even with postback. As long as you do not reload the page.

Rick D.
Contractor

"Smita" wrote:
Iam fairly new to .net programming. I have a listbox with multi-select
option. If page not postback, i do the data binding. On selection of values,
i save it in a session varible as this is used my couple of other pages. When
i traverse from the main page(where list box is created) to the sub pages and
come back , the value is lost and i do not have selected in the list box. Can
anyone please tell me what iam missing. I still have the values in the
session variable.
thanks in advance.
Jun 6 '07 #7
On Jun 6, 4:21 pm, dbgrick <dbgr...@discussions.microsoft.comwrote:
Smita,
Try enabling view state for the listbox control. This will maintain your
values, even with postback. As long as you do not reload the page.

Rick D.
Contractor
Rick.... the view state doesn't help - "When i traverse from the main
page(where list box is created) to the sub pages and
come back , the value is lost"

Jun 6 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wishing I was skiing mom | last post by:
Newbie to VB .NET. My solution contains an item maintenance screen, one of the fields on the screen is an item status, this field is defined as a listbox. The listbox item property contains a...
2
by: Simon P | last post by:
Hello group, I'm in desperate need of help. Here goes : I have the following tables : CONTACTS (ContactID, FirstName, LastName, Company, etc.), SHOWS (ShowID, ShowDescription) and SHOWDETAILS...
2
by: mathieu cupryk | last post by:
I have problems with listboxes in the webform2.cs, the textboxes are working well when I do a click on next. I am missing something. It works with the textboxes. Here is the file: using System;...
2
by: Mike P | last post by:
I have the following code in my Page_Load event to populate a listbox from a database : if (!(Page.IsPostBack)) { SqlConnection objConnection = new...
2
by: Gordon | last post by:
Hi; I am a novice asp.net developer who would like to create a dataset-table and then use the datatable.select cmd. to look up a value passed from the web calender control. The value(s) would...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
2
by: Big E | last post by:
I'm using ASP.Net and 1 Listbox and 1 ComboBox. When a user selects the contents in the listbox I want to populate the combobox with the text that he selected or double clicked. I've tried various...
1
by: Devin Wood | last post by:
Hi, I have a page with a ListBox on it, and It's also have a some buttons to populate the ListBox by using JavaScript. I have no problem with populate the listbox using JavaScript. But when the...
6
by: BerkshireGuy | last post by:
On an unbound form, I have a combobox called 'cboproducttype' and a text box called 'txtamountappliedfor'. I have an Add button that I would like the user to be able to hit once a product and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.