473,320 Members | 1,722 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,320 software developers and data experts.

DropDownList not maintaining viewstate

I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve
Nov 18 '05 #1
8 5195
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.DataSource = al;
DropDownList1.DataBind();

al.Add("dd");
DropDownList2.DataSource = al;
DropDownList2.DataBind();
}

[ASPX page]
<asp:DropDownList AutoPostBack="True" id="DropDownList1"
runat="server"></asp:DropDownList>
<asp:DropDownList AutoPostBack="True" id="DropDownList2"
runat="server"></asp:DropDownList>

Brun
"sklett" <as**@fkd.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve

Nov 18 '05 #2
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.DataSource = al;
DropDownList1.DataBind();

al.Add("dd");
DropDownList2.DataSource = al;
DropDownList2.DataBind();
}

[ASPX page]
<asp:DropDownList AutoPostBack="True" id="DropDownList1"
runat="server"></asp:DropDownList>
<asp:DropDownList AutoPostBack="True" id="DropDownList2"
runat="server"></asp:DropDownList>

Brun
"sklett" <as**@fkd.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve

Nov 18 '05 #3
That is really odd, I have 2-3 pages that all have the opposite behavior.

If I have a dropdownlist with 3 items, a, b, and c

Auto postback set to true

if I select 'b', when the page is rendered after the post back, 'a' is
selected.

I don't know what to do differently...
Thanks for the response though, looks like I have gremlins somewhere ;(
"Bruno Sirianni" <br***********@virgilio.it> wrote in message
news:5B*********************@news3.tin.it...
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.DataSource = al;
DropDownList1.DataBind();

al.Add("dd");
DropDownList2.DataSource = al;
DropDownList2.DataBind();
}

[ASPX page]
<asp:DropDownList AutoPostBack="True" id="DropDownList1"
runat="server"></asp:DropDownList>
<asp:DropDownList AutoPostBack="True" id="DropDownList2"
runat="server"></asp:DropDownList>

Brun
"sklett" <as**@fkd.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve


Nov 18 '05 #4
That is really odd, I have 2-3 pages that all have the opposite behavior.

If I have a dropdownlist with 3 items, a, b, and c

Auto postback set to true

if I select 'b', when the page is rendered after the post back, 'a' is
selected.

I don't know what to do differently...
Thanks for the response though, looks like I have gremlins somewhere ;(
"Bruno Sirianni" <br***********@virgilio.it> wrote in message
news:5B*********************@news3.tin.it...
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.DataSource = al;
DropDownList1.DataBind();

al.Add("dd");
DropDownList2.DataSource = al;
DropDownList2.DataBind();
}

[ASPX page]
<asp:DropDownList AutoPostBack="True" id="DropDownList1"
runat="server"></asp:DropDownList>
<asp:DropDownList AutoPostBack="True" id="DropDownList2"
runat="server"></asp:DropDownList>

Brun
"sklett" <as**@fkd.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve


Nov 18 '05 #5
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker</option>
<option value="2">Charlie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #6
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker</option>
<option value="2">Charlie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #7
Jim,

Yeah, that would be a fun one to find ;)
however, that is not the case for me. I set a breakpoint in the page_load
to check what the dropdown list's selected index was and it was correct IE:
if I had selected the 3rd item before postback, the SelectedIndex value was
2

but once the page is rendered... it's back to selecting the first item.

so strange.

Thanks for sharing your situation though, will come in handy some day!
"Jim Corey" <jc****@nospamcharter.net> wrote in message
news:OL**************@TK2MSFTNGP12.phx.gbl...
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker</option>
<option value="2">Charlie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #8
Jim,

Yeah, that would be a fun one to find ;)
however, that is not the case for me. I set a breakpoint in the page_load
to check what the dropdown list's selected index was and it was correct IE:
if I had selected the 3rd item before postback, the SelectedIndex value was
2

but once the page is rendered... it's back to selecting the first item.

so strange.

Thanks for sharing your situation though, will come in handy some day!
"Jim Corey" <jc****@nospamcharter.net> wrote in message
news:OL**************@TK2MSFTNGP12.phx.gbl...
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker</option>
<option value="2">Charlie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #9

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

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
4
by: sklett | last post by:
I have 2 dropdownlist on a page. They have ViewState = true. After I submit to the page, the selection in the DropDownList is lost. I set a break in the Page_Load event to make sure that I...
10
by: Phuff | last post by:
Thanks in advance! I'm trying to maintain a dl list's selected index on postback. What I'm doing is when a person selects an item from the drop down list I select a date in a calendar control and...
7
by: AG | last post by:
Hi, ASP.NET 2.0 web app I have a GridView utilizing template columns and bound to an objectdatasource. In the edit template of one column there is a dropdownlist bound to another...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.