0

I am using the below code to populate a dropdown on a selection of another dropdown. But somehow, ddlSubTypes is not getting populated when a item is selected in ddlTypes

On selectedindex change event of ddlTypes, i am binding 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
Anuya
  • 8,082
  • 49
  • 137
  • 222

1 Answers1

0

you should add a trigger to the second update panel that gets triggered on the first dropdown's selectedIndexChanged event.

<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>
Mutu Yolbulan
  • 1,052
  • 1
  • 8
  • 21
  • i am getting this error : Could not find an event named 'ddlTypes_SelectedIndexChanged1' on associated control 'ddlTypes' for the trigger in UpdatePanel 'UP2'. – Anuya Aug 13 '12 at 07:16
  • well you have to create the event server side. right now the trigger can't find an event that is handled server side. – Mutu Yolbulan Aug 13 '12 at 07:17
  • Create an event !!! I just put the selectedindexchange event name of my first dropdown to the EvenName of my second dropdwon. wrong is it ? – Anuya Aug 13 '12 at 07:20
  • in your code behind page is there an event with the name that you are using in the trigger? that's the error you are getting – Mutu Yolbulan Aug 13 '12 at 07:27