I am fairly new to asp.net, and am using it with Visual Studio 2013. I have a system where people are going to download some data from a database. To do this, I would like to have two drop down lists. One for the zip code, and another for the MonitorID.
The zip code dropdown list is databound to show all of the distinct zip codes. The monitor id dropdown list is databound to show all of the monitor ids that are contained in the zip code selected from the first dropdown.
I would like to have the MonitorID list change depending on what is selected in the zip code list. I have read that UpdatePanels are a good way to do this. I have gone through forum posts, and feel like I am close to getting this working, but something just is not connecting properly, and I am not sure what. Below is my code:
<form id="rawDataForm" runat="server"><asp:ScriptManager ID="RawDataScriptManager" runat="server" EnablePageMethods="True"></asp:ScriptManager><asp:UpdatePanel ID="Outter_Zip" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional"><ContentTemplate><asp:DropDownList ID="DropDownListZip" runat="server" DataSourceID="DistinctZip" DataTextField="Zip" DataValueField="Zip" AutoPostBack="True" OnSelectedIndexChanged="DropDownListZip_SelectedIndexChanged"></asp:DropDownList><asp:SqlDataSource ID="DistinctZip" runat="server" ConnectionString="<%$ ConnectionStrings:VOCMSConnectionString %>" SelectCommand="SELECT DISTINCT [Zip] FROM [Monitor]"></asp:SqlDataSource><asp:UpdatePanel ID="Inner_Monitor" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional"><ContentTemplate><asp:DropDownList ID="DropDownListMonitor" runat="server" AutoPostBack="True" DataSourceID="MonitorFromZip" DataTextField="MonitorID" DataValueField="MonitorID"></asp:DropDownList><asp:SqlDataSource ID="MonitorFromZip" runat="server" ConnectionString="<%$ ConnectionStrings:VOCMSConnectionString %>" SelectCommand="SELECT [MonitorID] FROM [Monitor] WHERE ([Zip] = @Zip)"><SelectParameters><asp:FormParameter DefaultValue="97601" FormField="DropDownListZip" Name="Zip" Type="String" /></SelectParameters></asp:SqlDataSource></ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="DropDownListZip" EventName="SelectedIndexChanged" /></Triggers></asp:UpdatePanel></ContentTemplate></asp:UpdatePanel>
What other settings do I need to have set correctly? Anything to do with postbacks? I have a trigger on the Inner_Monitor update panel set to asyncpostback when the DropDownListZip selectedindex changes. Do I need to do all the work in the .cs file in the DropDownListZip_SelectedIndexChanged() function?