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.
Alexey Smirnov - 05 Jun 2007 20:46 GMT
> 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,
[quoted text clipped - 4 lines]
> session variable.
> thanks in advance.
You should select the value of the list again.
ListBox.Items.FindByValue(Session["MyListValue"].ToString()).Selected
= true;
XOR - 06 Jun 2007 09:08 GMT
When you say come back - do you mean use the back button?
Siva M - 06 Jun 2007 10:11 GMT
Selection will be maintained only within the same page postback (of course,
view state should have been enabled) not across page navigations.
> 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,
[quoted text clipped - 4 lines]
> session variable.
> thanks in advance.
Alexey Smirnov - 06 Jun 2007 11:03 GMT
> 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.
Peter Bromberg [C# MVP] - 06 Jun 2007 12:41 GMT
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
> 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,
[quoted text clipped - 4 lines]
> session variable.
> thanks in advance.
dbgrick - 06 Jun 2007 15:21 GMT
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
> 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,
[quoted text clipped - 4 lines]
> session variable.
> thanks in advance.
Alexey Smirnov - 06 Jun 2007 15:48 GMT
> 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"