有两个DropDownList.前一个是部门,后一个是职务.选择部门后出来相应职务,这个已经可以了.但对于职务DropDownList 的 OnSelectedIndexChanged在两个部门的职务相同的情况下不执行.比如:有a,b两个部门.选择a部门之后出来M职务,选择M职务,这个时候OnSelectedIndexChanged执行.之后在选择b部门再选择M职务这个时候职务DropDownList的OnSelectedIndexChanged不执行,和解?谢谢
调试欢乐多
http://ajax.schwarz-interactive.de/csharpsample/default.aspx
请楼主确定下 职务DropDownList 绑定项的值都是唯一的.一般情况下,
当设置 DropDownList 的 AutoPostBack="true" 时,
就应该保证 DropDownList 的所有项的值都是唯一的,
以保证服务器端能正确触发相关事件.
也许有帮助Now, it is possible to send any HtmlControl to the server-side method, use C# to change properties on it and return the object to the client. A lot of developers are afrait of writing Javascript code. I have added a small function that will update any HtmlControl.Let's have a look at the server-side method. We will have two HtmlSelect controls on the page (DropDown):<select id="sel1" onchange="test19(this.value);">
<option value="">- Please select car -</option>
<option value="VW">VW (Volkswagen)</option>
<option value="Citroen">Citroen</option>
<option value="Mercedes">Mercedes-Benz</option>
</select>
<span id="dropDisplay">
<select>
<option value="">- Please select car first -</option>
</select>#
</select>The first drop down list will display some car companies. The second one will be filled after changing the car company in the first one. In the onchange event we will call following code. Note: the second element is embedded in a parent control. I did not find a good solution that works in all common browsers. This will be changed in future releases!The C# method will get the second drop down element as first argument, the second argument will be the selected value from the first drop down:[Ajax.AjaxMethod]
public System.Web.UI.HtmlControls.HtmlSelect Test19(string car)
{
System.Web.UI.HtmlControls.HtmlSelect control = new System.Web.UI.HtmlControls.HtmlSelect(); switch(car)
{
case "VW":
control.Items.Add("Golf");
control.Items.Add("Passat");
control.Items.Add("Beetle");
control.Items.Add("Phaeton");
break; case "Mercedes":
control.Items.Add("S Class");
control.Items.Add("E Class");
control.Items.Add("A Class");
control.Items.Add("M Class");
break; case "Citroen":
control.Items.Add("C3 Pluriel");
control.Items.Add("C5 Break");
control.Items.Add("C8");
control.Items.Add("Berlingo");
break;
} return control;
}The special function HtmlControlUpdate will get the Ajax.NET method as a string, the element to be updated and the optional arguments used for the C# method. In our example we will update the same control that we also send to the server:<script type="text/javascript">
function test19(car)
{
HtmlControlUpdate('DemoMethods.Test19', 'dropDisplay', car);
}
</script>Try it, now! If you change the car company you will get a new drop down list with the available models: