473,473 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

dropdown problem with setting selected values

Hi,

I'm trying to write a web page containing three dropdowns. The
dropdowns are declared as follows:

<asp:DropDownList id="cmbCat1" runat="server"
AutoPostBack="true"></asp:DropDownList>
<asp:DropDownList id="cmbCat2" runat="server"
AutoPostBack="True"></asp:DropDownList>
<asp:DropDownList id="cmbCat3" runat="server"
AutoPostBack="True"></asp:DropDownList>

When trying to set a selected value to each of them, the others are
influenced for some reason. Their selected value is set as well. This
is the code:

cmbCat1.SelectedValue = Session["cat1"].ToString();
cmbCat2.SelectedValue = Session["cat2"].ToString();
cmbCat3.SelectedValue = Session["cat3"].ToString();

Any ideas why this is happening and what I need to do to make them
independant?

Thanks!

Dec 3 '05 #1
7 1512
Without more information my suggestion would be to take a look at where you
set those session variables. Make sure they aren't all being set to the
same value.

--

Derek Davis
dd******@gmail.com

<se*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,

I'm trying to write a web page containing three dropdowns. The
dropdowns are declared as follows:

<asp:DropDownList id="cmbCat1" runat="server"
AutoPostBack="true"></asp:DropDownList>
<asp:DropDownList id="cmbCat2" runat="server"
AutoPostBack="True"></asp:DropDownList>
<asp:DropDownList id="cmbCat3" runat="server"
AutoPostBack="True"></asp:DropDownList>

When trying to set a selected value to each of them, the others are
influenced for some reason. Their selected value is set as well. This
is the code:

cmbCat1.SelectedValue = Session["cat1"].ToString();
cmbCat2.SelectedValue = Session["cat2"].ToString();
cmbCat3.SelectedValue = Session["cat3"].ToString();

Any ideas why this is happening and what I need to do to make them
independant?

Thanks!

Dec 5 '05 #2
I would also like to know where your combo's are getting populated
from. Are you data-binding them to a datatable in code behind?
If so, is it the same data table for all 3? If so, thats probably your
problem. Otherwise as carion suggested... your 3 session variables
might be the 1 object.

Steven Nagy

Dec 5 '05 #3

Steven Nagy wrote:
I would also like to know where your combo's are getting populated
from. Are you data-binding them to a datatable in code behind?
If so, is it the same data table for all 3? If so, thats probably your
problem. Otherwise as carion suggested... your 3 session variables
might be the 1 object.

Steven Nagy


Hi,
I'm not databinding them, but I'm inserting Items in a loop. The items
I'm inserting are the same because these three combos should contain
the same data. So what I'm doing is creating a listitem and adding it
to all three combos. Do you think this might be the problem?

Thanx

Dec 5 '05 #4
Hi,
Actually my first guess was that something was wrong w. the session
variables, so I tries setting the selected values to hard coded values,
but I got the same result...

Thanx

Dec 5 '05 #5
Almost definately.

The list item is a reference type, which means you are adding the same
object to all 3 lists.
Try creating an individual object for each one.

Steven Nagy

Dec 5 '05 #6
That was it.

Thanks a lot!!!

Dec 6 '05 #7
No problems.

The same issue applies in Windows Applications as well.

Any other cases where you want to use 1 data table for 3 different
combos, you can either have 3 data tables OR 1 data table and 3 data
views.
This is not relevant for you of course, but I thought I would post it
anyway in case someone else was looking for a solution to something
similar and their searches took them here.

Steven Nagy

Dec 7 '05 #8

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

Similar topics

1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
2
by: tmeister | last post by:
I must be missing something obvious. I have a drop down list in asp.net and it populates the states from a database. When I view the source of the page I get the standard option tags with the...
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...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
13
by: Shutey | last post by:
I have a strange issue with dropdowns. Using php4, mySQL5, Apache 2 on a fast XP pro PC, I have a form which requires 5 dropdowns populated with indentical values. I extract the values using SQL...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
2
by: raaman rai | last post by:
i have 3 drop dropdown box which is used for searching my database. Either one of them can be selected to perform the search but if none of them is selected it will give an error. Well in reference...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.