ASP.NET AJAX UpdatePanel下拉列表问题

时间:2014-02-28 08:27:58

标签: c# asp.net ajax

我有2个下拉列表(DDL),下面是一个asp.net ajax updatepanel,我想根据2 DDL中的选择更新/刷新。 第二个DDL的内容取决于第一个DDL中选择的内容。

问题在于,如果我在第一个DDL中选择了某些东西,它就不会填充第二个DDL,但如果没有ajax updatepanel,它就可以完美地运行。请尽可能提供帮助。下面是代码。感谢。

<asp:DropDownList runat="server" ID="ddlPrimary" AutoPostBack="true" OnSelectedIndexChanged="ddlPrimary_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList runat="server" ID="ddlSecondary" AutoPostBack="true" OnSelectedIndexChanged="ddlSecondary_SelectedIndexChanged"></asp:DropDownList>

<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
         <!-- asp.net repeater with table -->
         <tr>
              <td>
                  <asp:Label runat="server" ID="lblProdCode" Text='<%# Eval("ProdCode") %>'></asp:Label>
              </td>
              <td>
                  <asp:Label runat="server" ID="lblProdDesc" Text='<%# Eval("ProdDesc") %>'></asp:Label>
          </tr>
    </ContentTemplate>
    <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlPrimary" EventName="SelectedIndexChanged" />
                <asp:AsyncPostBackTrigger ControlID="ddlSecondary" EventName="SelectedIndexChanged" />
     </Triggers>
 </asp:UpdatePanel> 

1 个答案:

答案 0 :(得分:0)

如果您将2 DDL移动到UpdatePanel并删除触发器标记,就可以了:

<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
     <!-- asp.net repeater with table -->
<asp:DropDownList runat="server" ID="ddlPrimary" AutoPostBack="true" OnSelectedIndexChanged="ddlPrimary_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList runat="server" ID="ddlSecondary" AutoPostBack="true" OnSelectedIndexChanged="ddlSecondary_SelectedIndexChanged"></asp:DropDownList>

     <tr>
          <td>
              <asp:Label runat="server" ID="lblProdCode" Text='<%# Eval("ProdCode") %>'></asp:Label>
          </td>
          <td>
              <asp:Label runat="server" ID="lblProdDesc" Text='<%# Eval("ProdDesc") %>'></asp:Label>
      </tr>
</ContentTemplate>