2015-05-04 5 views
0

Я знаю, что здесь есть много вопросов по этой проблеме. Итак, ничто из того, что я просматривал, не помогло, поэтому я объясню возникшую у меня проблему и способы, которые я сам пытался решить.Событие OnSelectedIndexChanged не срабатывает

Я создал таблицу с двумя элементами управления asp.net DropDownList (ddlFaculty и ddlCourse), идея заключается в том, что, когда ddlFaculty имеет индекс изменился, который будет заполнен ddlCourse с соответствующими пунктами через AJAX. Если я установил autopostback в true на ddlCourse, тогда страница перезагрузится, поэтому я знаю, что это должно быть связано с самим элементом управления или с кодом, находящимся за файлом.

Вот мои два выпадающих списка:

ddlFaculty

<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> 

И ddlCourse

<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; 
      } 
    } 

Sc ript manager (в основном файле)

<asp:ScriptManager runat="server"> 
     <Scripts> 
      <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%> 
      <%--Framework Scripts--%> 
      <asp:ScriptReference Name="MsAjaxBundle" /> 
      <asp:ScriptReference Name="jquery" /> 
      <asp:ScriptReference Name="bootstrap" /> 
      <asp:ScriptReference Name="respond" /> 
      <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" /> 
      <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" /> 
      <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" /> 
      <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" /> 
      <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" /> 
      <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" /> 
      <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" /> 
      <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" /> 
      <asp:ScriptReference Name="WebFormsBundle" /> 
      <%--Site Scripts--%> 
     </Scripts> 
    </asp:ScriptManager> 

Я не слишком уверен, что еще я могу попробовать.

+0

только контроль, который должен быть обновлен идет в панели –

+0

Это может быть работа исследование наборов инструментов управления ASP.NET Ajax 'CascadingDropdown control http://www.ajaxcontroltoolkit.com/CascadingDropDown/CascadingDropDown.aspx –

ответ

0

Я думаю, что ваше мероприятие работает, но оно вызывает ошибку. то панель обновления не будет обновляться.

проверить для петель условие, кроме первой один

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

изменения я < = к я <

+0

спасибо за совет, потому что это одна ошибка, но это тоже не работает. –

+1

Проверьте вкладку сети браузера в инструментах разработчика. Является ли какой-либо запрос отправляться на сервер во время выборки выбора? –

0

Вы используете ScriptManager? например

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 

(Примечание: Я скопировать и вставить код в новый проект The только 2 изменения, которые я должен был сделать было (1) поставить вар перед вашими 6 деклараций массива (2) добавил ScriptManager.. Работал сразу для меня!)

+0

Iv только что обновил мой вопрос и добавил менеджера скриптов th Я использую, я пробовал вары, но все тот же. Если он работает для вас, то это указывает на менеджера сценариев как на виновника? –