使用onchange方法不能使用级联下拉列表 [英] Not working cascading dropdown with onchange method

查看:136
本文介绍了使用onchange方法不能使用级联下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我只使用级联DropDown列表然后它正常工作...我想显示和隐藏div id取决于下拉控件的列表项...我用onchange方法执行此任务但不工作...但它的没有级联的工作....



我尝试过:



if i use only cascading DropDown list then its proper work... i want to show and hide div id depend upon list item of dropdown control... i do this task with onchange method but not working... but its work without cascading....

What I have tried:

       function CourseFun() {

           debugger

           var DropdownList = document.getElementById('<%=course.ClientID %>');

           var SelectedIndex = DropdownList.selectedIndex;
           var divEQ = document.getElementById('divEQ')
           var divtenper = document.getElementById('divtenper');
           var divyear10 = document.getElementById('divyear10');
           var divpertwelth = document.getElementById('divpertwelth');
           var divyearof12 = document.getElementById('divyearof12');
           var divgraper = document.getElementById('divgraper');
           var divyearofgra = document.getElementById('divyearofgra');

           if (SelectedIndex == 1) {
               divEQ.style.display = "block";
               divpertwelth.style.display = "block";
               divyearof12.style.display = "block";
               divgraper.style.display = "none";
               divyearofgra.style.display = "none";
               divyear10.style.display = "block";
               divtenper.style.display = "block";
           }
           else if (SelectedIndex == 3) {
               divEQ.style.display = "block";
               divpertwelth.style.display = "block";
               divyearof12.style.display = "block";
               divyear10.style.display = "block";
               divtenper.style.display = "block";
               divgraper.style.display = "none";
               divyearofgra.style.display = "none";
           }
           else if (SelectedIndex == 2) {
               divEQ.style.display = "block";
               divyearofgra.style.display = "block";
               divpertwelth.style.display = "block";
               divyearof12.style.display = "block";
               divyear10.style.display = "block";
               divtenper.style.display = "block";
               divgraper.style.display = "block";

           }

       }




<asp:DropDownList ID="course" runat="server"  class="slectbig" AutoPostBack="true" OnSelectedIndexChanged="course_SelectedIndexChanged" onChange="CourseFun()" >
    <asp:ListItem Value="0"> Select course

推荐答案

设置 AutoPostBack =true表示一旦你更改了所选项目,页面就会回发到服务器。



CourseFun 函数可能运行,但它所做的任何更改都将被丢弃。



您需要触发 CourseFun 在页面加载时起作用。
Setting AutoPostBack="true" means that the page will post back to the server as soon as you change the selected item.

The CourseFun function might run, but any changes it makes will be discarded.

You need to trigger the CourseFun function when the page loads instead.


这篇关于使用onchange方法不能使用级联下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆