I am making a website in asp.net and I have 2 list boxes:
lbxPlayer1 and lbxPlayer2
lbxPlayer1.Items.Add("bob");
lbxPlayer1.Items.Add("jack");
lbxPlayer1.Items.Add("sam");
lbxPlayer2.Items.Add("fred");
lbxPlayer2.Items.Add("brian");
lbxPlayer2.Items.Add("dave");
they have both been populated with the same amount of values and i would like it so that when one of the lists is clicked the other list will select the same index.
how do i do this? i assume the code would be in the lbxPlayer1_SelectedIndexChanged event?
so when i click on "jack" i want "Brian" to also be selected.
Use the
SelectedIndex
property:If
SelectionMode
isMultiple
:Update
Only databind them
if(!IsPostBack)
sinceViewState
will retain items across postbacks. So i assume that this event is never triggered because you rebind theListBoxes
on postbacks.