"tranky" <NO****@GRAZIE.itwrote in message
news:47***********************@reader3.news.tin.it ...
I've 3 dropdownlist in an asp.net web page and c# in the codebehind.
Every dropdownlist have 10 elements.
I'd like using Ajax to change in a synchronized way the index of
dropdownlists.
For example, if i click the second dropdonwlist and i select the index
number 3, i'd like that also the first and the third dropdownlist will
change and positioning int the same index element.
Well, AJAX is probably overkill for such a task, since it could be more
directly accomplished by means of simple javascript, without needing to
communicate with the server. But if you still want to use Microsoft AJAX and
server-side code, do the following:
Add a ScriptManager Control and an UpdatePanel to the aspx page. Place
the three dropdownlists inside the UpdatePanel. Set to true the AutoPostBack
property in the three dropdownlists. Connect the SelectedIndexChanged event
of DropDownList1 to this routine:
void DropDownList1_IndexChanged(Object sender, EventArgs e) {
DropDownList3.SelectedIndex=DropDownList2.Selected Index=DropDownList1.SelectedIndex;
}
This will cause the second and third listboxes to adopt the same position
as the first one when this one changes. You can repeat the preceding with
dropdownlist2 and 3 so that changing any of them will chage the other two.
Be careful with your Page_Load: if you are loading the three
dropdownlists here, make sure that you are doing it inside an "if
(!IsPostBack)", otherwise you will reload the dropdowns on every postback
and this will lose you the SelectedIndex, so the indexchanged events will
not work as expected.