下拉列表未绑定内部Ajax更新面板

时间:2012-08-13 07:03:05

标签: asp.net .net ajax updatepanel scriptmanager

我使用以下代码填充另一个下拉列表中的下拉列表。 但不知何故,当在ddlTypes中选择一个项目时,ddlSubTypes没有被填充

在ddlTypes的selectedindex更改事件中,我绑定了ddlSubTypes。

<tr>
    <td class="style3">
        <asp:ScriptManager ID="scma" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UP1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="ddlTypes" runat="server" Width="200px" AutoPostBack="true" OnSelectedIndexChanged="ddlTypes_SelectedIndexChanged1">
                </asp:DropDownList>
            </ContentTemplate>
        </asp:UpdatePanel>
    </td>
</tr>
<tr>
    <td class="style3">
        <asp:UpdatePanel ID="UP2" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="ddlSubTypes" runat="server" Width="200px">
                </asp:DropDownList>
            </ContentTemplate>
        </asp:UpdatePanel>
    </td>
</tr>



Protected Sub ddlTypes_SelectedIndexChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTypes.SelectedIndexChanged
        Try
            'Populate schemes
            ddlSubTypes.Items.Clear()
            Dim ID As Integer = ddlTypes.SelectedValue
            Dim dt As DataTable = IterateSubtypesContents(ID)

            ddlSubTypes.DataTextField = dt.Columns("Type").ToString()
            ddlSubTypes.DataValueField = dt.Columns("ID").ToString()
            ddlSubTypes.DataSource = dt
            ddlSubTypes.DataBind()

            UP2.Update()
        Catch ex As Exception

        End Try
    End Sub

1 个答案:

答案 0 :(得分:0)

您应该在第一个下拉列表的selectedIndexChanged事件中触发第二个更新面板添加触发器。

<asp:UpdatePanel ID="UP2" runat="server">
  <ContentTemplate>
    <asp:DropDownList ID="ddlSubTypes" runat="server" Width="200px">
    </asp:DropDownList>
   </ContentTemplate>
   <Triggers>
     <asp:AsyncPostBackTrigger ControlID="Control That Triggers this Panel" EventName="Desired Event that triggers" />
   </Triggers>
</asp:UpdatePanel>