C# OnSelectedIndexChanged事件未触发

C# OnSelectedIndexChanged事件未触发,c#,asp.net,C#,Asp.net,我知道这里有很多关于这个问题的问题。所以,我所搜索的一切都没有帮助,所以我将解释我遇到的问题以及我自己试图解决这个问题的方法 我创建了一个带有两个asp.net DropDownList控件(DDLFuncil和ddlCourse)的表,其思想是当DDLFuncil的索引发生更改时,将通过AJAX用相应的项填充ddlCourse。如果我在ddlCourse上将autopostback设置为true,则“页面将重新加载,因此我知道它一定与控件本身或代码隐藏文件有关。” 以下是我的两个下拉列表: 能

我知道这里有很多关于这个问题的问题。所以,我所搜索的一切都没有帮助,所以我将解释我遇到的问题以及我自己试图解决这个问题的方法

我创建了一个带有两个asp.net DropDownList控件(DDLFuncil和ddlCourse)的表,其思想是当
DDLFuncil
的索引发生更改时,将通过AJAX用相应的项填充
ddlCourse
。如果我在
ddlCourse
上将
autopostback
设置为true,则“页面将重新加载,因此我知道它一定与控件本身或代码隐藏文件有关。”

以下是我的两个下拉列表:

能力

<asp:DropDownList ID="ddlFaculty" class="form-control" runat="server" data-toggle="dropdown" aria-expanded="true" OnSelectedIndexChanged="ddlFaculty_SelectedIndexChanged" AutoPostBack="true">
    <asp:ListItem>Select Faculty</asp:ListItem>
    <asp:ListItem Value="Faculty of Arts">Faculty of Arts</asp:ListItem>
    <asp:ListItem Value="Faculty of Business">Faculty of Business</asp:ListItem>
    <asp:ListItem Value="Faculty of Health">Faculty of Health</asp:ListItem>
    <asp:ListItem Value="Faculty of ">Faculty of Health</asp:ListItem>
    <asp:ListItem Value="Faculty of Service Industries">Faculty of Service Industries</asp:ListItem>
    <asp:ListItem Value="Faculty of Trades">Faculty of Trades</asp:ListItem>
    <asp:ListItem Value="Te Wananga Maori">Te Wananga Maori</asp:ListItem>
</asp:DropDownList>

挑选教员
文学院
商学院
卫生学院
卫生学院
服务业学院
贸易学院
特瓦南加毛利人
当然

<asp:UpdatePanel ID="updateCourse" runat="server">
    <ContentTemplate>
        <asp:DropDownList ID="ddlCourse" class="form-control" runat="server" data-toggle="dropdown" aria-expanded="true">                  
        </asp:DropDownList>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlFaculty" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>

以及要在代码隐藏文件中调用的方法

 protected void ddlFaculty_SelectedIndexChanged(object sender, EventArgs e)
{        
    switch (ddlFaculty.SelectedIndex)
    {

            case 1:
            {
                Arts = new string[]
                {
                    "Adobe Creative Suite", "Bachelor of Applied Arts (Creative Writing)", "Bachelor of Applied Arts (Music)", "Bachelor of Applied Arts (Performing Arts)",
                    "Bachelor of Applied Arts (Visual Arts and Design)", "Bachelor of Teaching (Early Childhood Education)", "Certificate in Advanced Photography",
                    "Certificate in Desktop Publishing for Print and the Web", "Certificate in Digital Media", "Certificate in DJ Music", "Certificate in Foundation Music",
                    "Certificate in Live Sound and Event Production", "Certificate in Mastercraft", "Certificate in Multimedia Journalism", "Certificate in Practical Photography",
                    "Certificate in Professional Teaching Practice(English)", "Certificate in Rock, Jazz and Commercial Music", "Certificate in Screen Acting",
                    "Diploma in Applied Stage and Screen Arts(Advanced)", "Diploma in Creative Writing", "Diploma in Creative Writing(Advanced)", "Diploma in Digital Design",
                    "Diploma in Digital Design and Multi - media", "Diploma in Early Childhood Education", "Diploma in Jewellery Design", "Diploma in Performing Arts(Commercial Dance)",
                    "Diploma in Performing Arts: Singing(Musical Theatre)", "Diploma in Publishing", "Diploma in Publishing(Applied)", "Diploma in Stage and Screen Arts",
                    "Graduate Diploma in Creative Writing", "National Diploma in Journalism(Multi - media)(Level 5)", "The Creative Writing Programmes Introduction"
                };

                for (int i = 0; i < Arts.Length; i++)
                {
                    ddlCourse.Items.Add(Arts[i]);
                }
                break;
            }
            case 2:
            {
                Business = new string[]
                {
                   "Bachelor of Applied Business Studies", "Bachelor of Information Technology", "Certificate in English Language", "Certificate in English Language (Advanced)",
                   "Certificate in Information Technology", "Diploma in Information Technology (Level 5)", "Diploma in Information Technology (Level 6)", "Diploma in Management (Not for Profit Sector)",
                   "Graduate Diploma in Applied Business Studies", "Graduate Diploma in Information Technology", "New Zealand Diploma in Business", "New Zealand Institute of Management (NZIM)Certificate in Management",
                   "New Zealand Institute of Management (NZIM)Certificate in Small Business Management", "New Zealand Institute of Management (NZIM)Diploma in Management",
                   "New Zealand Law Society Legal Executive Diploma"
                };

                for (int i = 0; i <= Business.Length; i++)
                {
                    ddlCourse.Items.Add(Business[i]);
                }
                break;
            }
            case 3:
            {
                Health = new string[]
                {
                    "Bachelor of Health Science (Paramedic)", "Bachelor of Nursing", "Bachelor of Nursing Māori", "Bachelor of Nursing Pacific",
                    "Bachelor of Social Work", "Certificate in Foundation Education (Health Science)", "Certificate in Foundation Education (Social Sciences)",
                    "Certificate in Health Professional Practice Development", "Certificate in Nursing (Long Term Care and Rehabilitation)",
                    "Certificate in Preparation for Tertiary Study", "Competency Assessment Programme for Nurses", "National Certificate in Mental Health(Mental Health Support Work)",
                    "National Certificate in Tamariki Ora – Well Child Services", "National Diploma in Mental Health(Mental Health Support Work)",
                    "Postgraduate Certificate in Hospice Palliative Care", "Postgraduate Certificate in Nursing", "Postgraduate Certificate in Perioperative Specialty Nursing",
                    "Postgraduate Certificate in Primary Health Care Specialty Nursing", "Postgraduate Certificate in Specialty Care", "Pre - entry to Degrees"
                };

                for (int i = 0; i <= Health.Length; i++)
                {
                    ddlCourse.Items.Add(Health[i]);
                }
                break;
            }
            case 4:
            {
                Industries = new string[]
                {
                    "Certificate in Beauty and Hairdressing", "Certificate in Beauty Therapy", "Certificate in Cafe Service", "Certificate in Office Administration and Computing (Advanced)",
                    "Certificate in Office Administration and Computing (Intermediate)", "Certificate in Office Administration and Computing (Introductory)",
                    "Certificate in Office Skills/Computing", "Certificate in Outdoor Adventure", "Certificate in Professional Cookery", "Certificate in Retail and Cosmetic Services",
                    "Certificate in Retail Management", "Community Computing", "Diploma in Outdoor Adventure", "Flexi-Learn Computer Applications","Mountain Safety Council Courses",
                    "National Certificate Business (First Line Management) Level 3", "National Certificate in Computing (Level 2 and 3)", "National Certificate in Hairdressing (Salon Support)",
                    "National Certificate in Tourism (Core Skills) Level 3", "National Diploma in Hospitality (Management) (Level 5)", "Short Course Certificate in Avalanche Safety",
                    "Short Course Certificate in Computer Applications"
                };

                for (int i = 0; i <= Industries.Length; i++)
                {
                    ddlCourse.Items.Add(Industries[i]);
                }
                break;
            }
            case 5:
            {
                Trades = new string[]
                 {
                    "Certificate in Automotive Engineering", "Certificate in Automotive Engineering (Advanced)", "Certificate in Aviation (Aeroplane)", "Certificate in Aviation (Aeroplane) Instructor Rating ",
                    "Certificate in Aviation (Helicopter)", "Certificate in Aviation (Helicopter) Advanced", "Certificate in Aviation (Helicopter) Turbine", "Certificate in Aviation (Multi-engine Instrument Rating)",
                    "Certificate in Carpentry", "Certificate in Civil Construction (Introductory Skills)", "Certificate in Commercial Road Transport", "Certificate in Electrical Engineering",
                    "Certificate in Horticulture and Landscaping", "Certificate in Plumbing, Drainlaying", "Gasfitting and Roofing", "Certificate in Road Transport",
                    "Certificate in Trade Skills", "National Certificate in Floristry (Level 2)"
                 };

                for (int i = 0; i <= Trades.Length; i++)
                {
                    ddlCourse.Items.Add(Trades[i]);
                }
                break;

            }
            case 6:
            {
                Maori = new string[]
                 {
                    "Certificate in General Studies", "Certificate in Mastercraft (Ngā Tapuwae o Hine-te-iwaiwa)",
                    "Certificate in Reo Māori – Te Ara Piko", "Certificate in Reo Māori – Tēnei Au", "Certificate in Waka Ama",
                    "Certificate in Waka Ama (Advanced)", "National Certificate in Whakairo (Tūturu) (Level 4)", "National Diploma in Reo Māori (Level 5)",
                    "National Diploma in Reo Māori (Level 6)", "National Diploma in Whakairo (Level 5)", "National Diploma in Whakairo (Level 6)",
                    "Te Hiringa o Te Reo"
                 };

                for (int i = 0; i <= Maori.Length; i++)
                {
                    ddlCourse.Items.Add(Maori[i]);
                }
                break;
            }
    }
protectedvoid\u SelectedIndexChanged(对象发送方,事件参数e)
{        
开关(DDL.SelectedIndex)
{
案例1:
{
Arts=新字符串[]
{
“Adobe创意套件”、“应用文学士(创意写作)”、“应用文学士(音乐)”、“应用文学士(表演艺术)”,
“应用艺术学士(视觉艺术与设计)”、“教学学士(幼儿教育)”、“高级摄影证书”,
《印刷与网络桌面出版证书》、《数字媒体证书》、《DJ音乐证书》、《基础音乐证书》,
“现场声音和活动制作证书”、“大师级证书”、“多媒体新闻证书”、“实用摄影证书”,
“专业教学实践证书(英语)”、“摇滚、爵士乐和商业音乐证书”、“银幕表演证书”,
「应用舞台及荧幕艺术文凭(高级)」、「创意写作文凭」、「创意写作文凭(高级)」、「数码设计文凭」,
"数码设计及多媒体文凭,"幼儿教育文凭,"珠宝设计文凭,"表演艺术文凭(商业舞蹈),,
"表演艺术文凭:歌唱(音乐剧),"出版文凭,"出版文凭(应用),"舞台及银幕艺术文凭",,
“创意写作研究生文凭”、“国家新闻(多媒体)(5级)”和“创意写作课程简介”
};
for(int i=0;i


(注意:我复制并粘贴了你的代码到一个新项目中。我只需要做两个更改:(1)在你的6个数组声明前面放一个变量(2)添加了ScriptManager。对我来说很有效!)

我想你的事件正在工作,但它会抛出错误。然后更新面板将不会更新

检查除第一个循环外的循环状况

for (int i = 0; i <= Industries.Length; i++)
{
    ddlCourse.Items.Add(Industries[i]);
}

用于(int i=0;i只有需要更新的控件才能进入面板它可能正在调查ASP.net Ajax控件工具包的CascadingDropdown控件Iv刚刚更新了我的问题并添加了我正在使用的脚本管理器,我尝试了vars,但仍然是一样的。如果它对您有效,那么我会指出脚本管理器是罪魁祸首它?谢谢你的建议,因为这是一个错误的方式,但也不工作。检查你的浏览器网络选项卡在开发工具。有任何请求发送到服务器,而下拉选择改变?
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
for (int i = 0; i <= Industries.Length; i++)
{
    ddlCourse.Items.Add(Industries[i]);
}