有两个DropDownList.前一个是部门,后一个是职务.选择部门后出来相应职务,这个已经可以了.但对于职务DropDownList 的 OnSelectedIndexChanged在两个部门的职务相同的情况下不执行.比如:有a,b两个部门.选择a部门之后出来M职务,选择M职务,这个时候OnSelectedIndexChanged执行.之后在选择b部门再选择M职务这个时候职务DropDownList的OnSelectedIndexChanged不执行,和解?谢谢

解决方案 »

  1.   

    第一个DropDownList的AutoPostBack设为true
      

  2.   

    你的M职位可能是默认的第1个,DropDownList必须在改变了下拉选择项才会引起OnSelectedIndexChanged, 在a的OnSelectedIndexChanged改变后你有没有重新加载b中的items
      

  3.   

    nextsun(一天啃一点) 的方法确实可以,不过这样页面就会刷新,还有其他方法吗,谢谢
      

  4.   

    如果你要不刷新的,那就要用Ajax来实现,可以下一个Ajax.Net框架来试试(我现在正在用)~~~
    http://ajax.schwarz-interactive.de/csharpsample/default.aspx
      

  5.   

    你没设置成AutoPostBack=true,你会执行后台的OnSelectedIndexChanged方法?不可能吧你现在是用什么实现的,AJAX?把你的代码贴出来看看
      

  6.   

    这种问题多是绑定数据的问题,
    请楼主确定下 职务DropDownList 绑定项的值都是唯一的.一般情况下,
    当设置 DropDownList 的 AutoPostBack="true" 时,
    就应该保证 DropDownList 的所有项的值都是唯一的,
    以保证服务器端能正确触发相关事件.
      

  7.   

    看看这个,具体实现在http://ajax.schwarz-interactive.de/csharpsample/default.aspx
    也许有帮助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:
      

  8.   

    你写的这个过程已经实现了,现在是选择第二个下拉时,如果选择项和上次的选择项同,不触发OnSelectedIndexChanged.而选择每次重新选择第一个下拉时第二个下拉时用ajax重新产生的.
      

  9.   

    你第二个下拉是动态添加选项的对不对?问题通常就出在这里。如果你在页面生命周期较后的阶段添加选项,那么这些选项在PostBack之后未能及时添加上去,于是就不存在SelectedIndex,那么当然也就不存在OnSelectedIndexChanged了。