dropdown problem with setting selected values

  • Thread starter Thread starter segal.aviad
  • Start date Start date
S

segal.aviad

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!
 
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.
 
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
 
Steven said:
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
 
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
 
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
 
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
 
Back
Top