使用下拉列表更新面板asp.net/c#

时间:2015-04-04 03:12:56

标签: c# asp.net drop-down-menu asp.net-ajax updatepanel

我正在尝试使用一个下拉列表中的选择来过滤另一个,使用更新面板,因此它不会刷新页面。但是,我无法让它发挥作用。

以下是代码:

ASPX(这低于所有JS内容):

     

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <a href="#" title="Select the module code (Mandatory Field)">Module Code*</a>
        <asp:DropDownList ID="ModuleCodeDDL" AutoPostBack="true" OnSelectedIndexChanged="ModuleCodeDDL_SelectedIndexChanged" Style="width: 200px;" runat="server"></asp:DropDownList>

        <a href="#" title="The name of the module e.g. 'Team Projects'. Mandatory Field.">Module Name*</a>
        <asp:DropDownList ID="ModuleTitleDDL" AutoPostBack="true" Style="width: 250px;" runat="server"></asp:DropDownList>
    </ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

背后的代码(C#): //我最初占据两个下降的位置

  connect.Open();

  string moduleSql = "Select Module_Code, Module_Title from [newModule]";
  SqlCommand moduleCommand = new SqlCommand(moduleSql, connect);
  SqlDataReader modules = moduleCommand.ExecuteReader();
  while (modules.Read())
  {
     string moduleCode = modules.GetString(0);
     string moduleName = modules.GetString(1);
     string module = moduleCode;
     ModuleCodeDDL.Items.Add(module);

     }
     connect.Close();

     connect.Open();

     string moduleSql1 = "Select Module_Code, Module_Title from [newModule]";
     SqlCommand moduleCommand1 = new SqlCommand(moduleSql1, connect);
     SqlDataReader modules1 = moduleCommand1.ExecuteReader();
     while (modules1.Read())
     {
     string moduleCode = modules1.GetString(0);
     string moduleName = modules1.GetString(1);
     string module = moduleName;
     ModuleTitleDDL.Items.Add(module);

     }
     connect.Close();
     }

//这是与ONSELECTEDINDEXCHANGED一起被召唤的功能

 protected void ModuleCodeDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection connect = new SqlConnection(WebConfigurationManager.ConnectionStrings["ParkConnectionString"].ToString());
        ModuleTitleDDL.Items.Clear();
        connect.Open();
        string moduleCode = ModuleCodeDDL.SelectedItem.Value;
        string moduleTitleSQL = "Select Module_Code, Module_Title From [newModule] Where Module_Code ='" + moduleCode + "'";
        SqlCommand moduleTitleNew = new SqlCommand(moduleTitleSQL, connect);
        SqlDataReader newModuleTitle1 = moduleTitleNew.ExecuteReader();
        ModuleTitleDDL.Items.Add("");
        while (newModuleTitle1.Read())//Add the results to the dropdownlist
        {
            ModuleTitleDDL.Items.Add(newModuleTitle1.GetString(1).ToString());
        }

        connect.Close();

    }

它在没有更新面板的情况下可以完整回发,但我似乎无法使用更新面板。 如果有人能够解释如何解决这个问题,我们将不胜感激。

提前致谢!

0 个答案:

没有答案