471,348 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

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 1447
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by middletree | last post: by
5 posts views Thread by Kris Rockwell | last post: by
2 posts views Thread by tmeister | last post: by
2 posts views Thread by Mike Collins | last post: by
13 posts views Thread by Shutey | last post: by
3 posts views Thread by John | last post: by

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.