473,406 Members | 2,371 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,406 software developers and data experts.

Dropdown List not retaining its SelectedValue

From: ju*********@yahoo.com
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Dropdown List not retaining its SelectedValue
Date: Mon, 26 Jun 2006 21:02:57 -0700

Hello,

My dropdown list control does not retain its SelectedValue. Unless I
read the SelectedValue right after the control has been loaded,
populated, and assigned with its original value (and of course that is
the time I absolutely do not need to read it's value) it alwasy returns
"".

I don't think it's a database or database binding issue, because it's
still not working when I tested with unbound dropdown list - the one
that I manually populated with simple integer sequence.

Here's a brief descript of how the application's structured. The main
window / web page creates an instance of this *.ascx class. Just
before the class is loaded in to the browser window, there's another
class that gets loaded first as a page header, where all the common
controls and user interaction pieces are implemented (like buttons and
stuff), and shared by all the *.ascx classes.

Once the head is loaded, all this class does is pretty much to figure
out which User Control to load in, and one of them is my *.ascx User
Control where this problematic dropdown list is in.

It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.

Once user makes a selection on the dropdown list and clicks on Save on
the header, the head class invokes the Save method in the main class,
which in turn calls up the Save method in my User Control. If I look
at the SelectedValue property of my dropdown list within this method
(when it's called), I can see that it has been reset back to "" (and
its selectedIndex has been reverted to 0).

What's weird is that all the other controls, like textboxes and labels,
still retain their values. It's just the dropdown list that gets reset
like this. What is going on????

I also have noticed that if I assign a value to a class variable inside
of the Display method, by the time when I tried to retrieve it in the
Save method, the value of the class variable becomes "undefined". This
makes no sense to me... It almost feels like I am calling methods on
different instacnes of the class, instead of on the same object.

I am very confused. Does this have something to do with one of those
State, Session, Persistance/Non Persistance object thingy that I kept
hearing about? Okay, if that's the case and I am indeed making method
calls on actually different instances of the same class, why am I able
to retrieve the values from some controls, but not this dropdown list?

???

Thank you very much in advance. Any comments and/or feedbacks will be
greatly appreciated.

Jun 27 '06 #1
5 11853
ju*********@yahoo.com wrote:
From: ju*********@yahoo.com
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Dropdown List not retaining its SelectedValue
Date: Mon, 26 Jun 2006 21:02:57 -0700

Hello,

My dropdown list control does not retain its SelectedValue. Unless I
read the SelectedValue right after the control has been loaded,
populated, and assigned with its original value (and of course that is
the time I absolutely do not need to read it's value) it alwasy returns
"".

I don't think it's a database or database binding issue, because it's
still not working when I tested with unbound dropdown list - the one
that I manually populated with simple integer sequence.

Here's a brief descript of how the application's structured. The main
window / web page creates an instance of this *.ascx class. Just
before the class is loaded in to the browser window, there's another
class that gets loaded first as a page header, where all the common
controls and user interaction pieces are implemented (like buttons and
stuff), and shared by all the *.ascx classes.

Once the head is loaded, all this class does is pretty much to figure
out which User Control to load in, and one of them is my *.ascx User
Control where this problematic dropdown list is in.

It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.

Once user makes a selection on the dropdown list and clicks on Save on
the header, the head class invokes the Save method in the main class,
which in turn calls up the Save method in my User Control. If I look
at the SelectedValue property of my dropdown list within this method
(when it's called), I can see that it has been reset back to "" (and
its selectedIndex has been reverted to 0).

What's weird is that all the other controls, like textboxes and labels,
still retain their values. It's just the dropdown list that gets reset
like this. What is going on????

I also have noticed that if I assign a value to a class variable inside
of the Display method, by the time when I tried to retrieve it in the
Save method, the value of the class variable becomes "undefined". This
makes no sense to me... It almost feels like I am calling methods on
different instacnes of the class, instead of on the same object.

I am very confused. Does this have something to do with one of those
State, Session, Persistance/Non Persistance object thingy that I kept
hearing about? Okay, if that's the case and I am indeed making method
calls on actually different instances of the same class, why am I able
to retrieve the values from some controls, but not this dropdown list?

???

Thank you very much in advance. Any comments and/or feedbacks will be
greatly appreciated.


Did you checked wither "EnableViewState" for this control is set to True?

If it is false then the control wont retain its selected value. You also
have to set "AutoPostBack" property of that control to "true".

-
Vadivel Kumar
http://vadivelk.net
Jun 27 '06 #2

Vadivel Kumar wrote:
ju*********@yahoo.com wrote:
From: ju*********@yahoo.com
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Dropdown List not retaining its SelectedValue
Date: Mon, 26 Jun 2006 21:02:57 -0700

Hello,

My dropdown list control does not retain its SelectedValue. Unless I
read the SelectedValue right after the control has been loaded,
populated, and assigned with its original value (and of course that is
the time I absolutely do not need to read it's value) it alwasy returns
"".

I don't think it's a database or database binding issue, because it's
still not working when I tested with unbound dropdown list - the one
that I manually populated with simple integer sequence.

Here's a brief descript of how the application's structured. The main
window / web page creates an instance of this *.ascx class. Just
before the class is loaded in to the browser window, there's another
class that gets loaded first as a page header, where all the common
controls and user interaction pieces are implemented (like buttons and
stuff), and shared by all the *.ascx classes.

Once the head is loaded, all this class does is pretty much to figure
out which User Control to load in, and one of them is my *.ascx User
Control where this problematic dropdown list is in.

It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.

Once user makes a selection on the dropdown list and clicks on Save on
the header, the head class invokes the Save method in the main class,
which in turn calls up the Save method in my User Control. If I look
at the SelectedValue property of my dropdown list within this method
(when it's called), I can see that it has been reset back to "" (and
its selectedIndex has been reverted to 0).

What's weird is that all the other controls, like textboxes and labels,
still retain their values. It's just the dropdown list that gets reset
like this. What is going on????

I also have noticed that if I assign a value to a class variable inside
of the Display method, by the time when I tried to retrieve it in the
Save method, the value of the class variable becomes "undefined". This
makes no sense to me... It almost feels like I am calling methods on
different instacnes of the class, instead of on the same object.

I am very confused. Does this have something to do with one of those
State, Session, Persistance/Non Persistance object thingy that I kept
hearing about? Okay, if that's the case and I am indeed making method
calls on actually different instances of the same class, why am I able
to retrieve the values from some controls, but not this dropdown list?

???

Thank you very much in advance. Any comments and/or feedbacks will be
greatly appreciated.


Did you checked wither "EnableViewState" for this control is set to True?

If it is false then the control wont retain its selected value. You also
have to set "AutoPostBack" property of that control to "true".

-
Vadivel Kumar
http://vadivelk.net


Jun 27 '06 #3
First of all, thank you for your reply.
Vadivel Kumar wrote:

Did you checked wither "EnableViewState" for this control is set to True?

Yes, it's been always set to True.

If it is false then the control wont retain its selected value. You also
have to set "AutoPostBack" property of that control to "true".


Well, for some long reason, I really can't set the AutoPostBack
property to True. However, as I said in my original posting, all the
other controls do retain their values and let me read them correctly
later (from inside of other method in the same class), and none of
these controls have AutoPostBack property set to True.

I wish I can try to set the AutoPostBack property to True and see what
happens, but... once I do that it screws up some other stuffs in other
places...

Would there be anything else that I can try?

Have a nice day.

Jun 27 '06 #4
<ju*********@yahoo.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.


Populate your DropDownList in Page_Init instead of Page_Load and all will be
well.
Jun 27 '06 #5

Mark Rae wrote:
<ju*********@yahoo.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.


Populate your DropDownList in Page_Init instead of Page_Load and all will be
well.


Okay... Actually, I have come across an article that mentioned
something like that (after spending hours searching for my answer in
the Usenet... Well, the problem was that it was a little bit too
complicated to understand. :)

Anyway, the real problem is this: In fact, I'm not even populating the
dropdown list in Page_Load. After the page (UserControl to be more
specific) is loaded into the parent page, the parent page gets all the
data (not just for the dropdown list but all the other controls) from
the database, and calls up a method with a DataSet that contains those
data as a parameter, then the method in the UserControl populates the
dropdown list.

Don't ask me why it's done this way. I am not the creator of this code
- I've only inherited it :( I will give it a try tomorrow. As a
matter of fact, I can't think of why the database queries should happen
at the parent page. Well, actually some parameters for some queries
have to come from outside, in which case the query can't happen in Init
state since the Page/UserControl can't receive those parameters from
its parent before it exists... But, at least for populating dropdown
list, I may be able to do so since all I need to do is retrieving the
entire table with two columns.

Thank you very much for your response. I will post back with how it
went.

Have a nice day.

Jun 29 '06 #6

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

Similar topics

3
by: Steven | last post by:
Hi there, I am having a problem with an ASP.NET DropDown list - whenever I set the SelectedValue (or SelectedIndex) property, when the page displays, only the first item is ever selected. This...
0
by: Frawls | last post by:
Hi, This is concerned with System.Web.UI.WebControls.DropDownList I am having problems creating a method which will remove list items from a preloaded dropdownlist. This dropdown is loaded...
1
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed...
6
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
5
by: =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= | last post by:
Hello. I am reading a value from a table and trying to determine if that value exists in a list of values associated with a dropdownlist. If so, I select the value, otherwise, I don't. I haven't...
2
by: JJ297 | last post by:
I have a dropdown list populated via a database. I edited the dropdown list to have "select a topic" to always appear when the drop down loads. Now if a user selects a dropdown item it goes into...
3
by: John | last post by:
I have two dropdown lists that I have bound to a datatable and set the DataTextField and DataValueField for. Both lists show the values I expect from the database. However, when I need to access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.