Necuno
Court Jester
- Joined
- Sep 27, 2005
- Messages
- 58,566
- Reaction score
- 3,437
the actual question is (since we don't have combo boxes in asp.net but rather drop down lists...hehe): if i have more than one dropdownlist with the same listitem collection and i change the second or third (and so on) 's selected index the previous dropdownlists before them also changes to their selected index for some odd reason - maybe i just need more coffee and an actual brake over time spent programming today 
...
this results in A, B and C having "d" as their selected item -

not sure why, but no where i actually have them all on the same reference as in A=B=C . I guess i'm missing the theory on why of this somewhere a long the line 
in the pageload for testing
source for the aspx
...
this results in A, B and C having "d" as their selected item -
in the pageload for testing
Code:
ListItem[] items = new ListItem[]
{
new ListItem("a", "a"), //0
new ListItem("b", "b"),
new ListItem("c", "c"),
new ListItem("d", "d"), //3
};
A.Items.AddRange(items);
B.Items.AddRange(items);
C.Items.AddRange(items);
A.SelectedIndex = 1;
B.SelectedIndex = 2;
C.SelectedIndex = 3;
source for the aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="A" runat="server">
</asp:DropDownList><br />
<br />
<asp:DropDownList ID="B" runat="server">
</asp:DropDownList><br />
<br />
<asp:DropDownList ID="C" runat="server">
</asp:DropDownList></div>
</form>
</body>
</html>
Last edited: