By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,969 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,969 IT Pros & Developers. It's quick & easy.

Listbox populate with session value

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
When you say come back - do you mean use the back button?
Jun 6 '07 #3

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.