title: Dependent DropDownList in FormView
body: <p>I am trying to create two drop down lists in a form view where the values that are displayed in the second drop down are dependent upon the first drop down.The first list contains the class numbers contained in a sql table "Classes" and the second drop down list contains the class sections in the same sql table "Classes". I want to be able to select a class number and only have the sections that correspond to that class number pop up. </p>
  
  <p>Example Classes Table:</p>
  
  <pre><code>Number:   Section:   SLN:  
  210       1          A-1  
  210       2          A-2  
  210       3          A-3  
  340       1          B-1  
  340       7          B-7 
  </code></pre>
  
  <p>I currently have the first list for Number set up properly using</p>
  
  <pre><code>   &lt;asp:DropDownList ID="ddlNumber" runat="server" 
      DataSourceID="SqlDSClasses"
       AutoPostBack="True" DataTextField="Number" DataValueField="Number"&gt;
      &lt;/asp:DropDownList&gt; 
  for the drop down and
  
  &lt;asp:SqlDataSource ID="SqlDSClasses" runat="server"       
  ConnectionString="&lt;%$ ConnectionStrings:ReinstatementCS %&gt;" 
  SelectCommand="SELECT [Prefix], [Number], [Location], [SLN],                              
  [StartTime], [EndTime], [ClassDay], [ClassCredit], [ClassSection] FROM [Classes]"&gt;   
  &lt;/asp:SqlDataSource&gt;
  for the corresponding SqlDataSource
  </code></pre>
  
  <p>So far I have tried to use</p>
  
  <pre><code>SELECT [ClassSection] FROM [Classes] WHERE [Number] = NumberDropDownList.DataValueField
  for the Section list:
  
  &lt;asp:DropDownList ID="ClassSectionDropDownList" runat="server" DataSourceID="SqlDSNumSec" 
                                              DataTextField="ClassSection" DataValueField="ClassSection"  AutoPostBack="True"&gt;
                                          &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>The Form View being used is set up as follows:</p>
  
  <pre><code>&lt;asp:FormView ID="FVStudentClass" runat="server" DataSourceID="SqlDSStudentClass"
                          DataSourceID2="SqlDSAccess" EmptyDataText="Student Class Not Completed"&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;table style="width:100%;"&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          Prefix:
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          UCOLL&lt;/td&gt;
                                      &lt;td&gt;
                                          Number:
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:DropDownList ID="ddlNumber" runat="server" DataSourceID="SqlDSClasses"  AutoPostBack="True"
                                              DataTextField="Number" DataValueField="Number"&gt;
                                          &lt;/asp:DropDownList&gt;
                                      &lt;/td&gt;
  
                                      &lt;td&gt;
  
                                          Section:
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:DropDownList ID="SectionDropDownList" runat="server" DataSourceID="SqlDSNumSec" 
                                              DataTextField="Section" DataValueField="Section"  AutoPostBack="True"&gt;
                                          &lt;/asp:DropDownList&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/table&gt;
                              &lt;asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                                  Text="Update" /&gt;
                              &amp;nbsp;&lt;asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
                                  CommandName="Cancel" Text="Cancel" /&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;InsertItemTemplate&gt;
                              IsTransfer:
                              &lt;asp:CheckBox ID="IsTransferCheckBox" runat="server" 
                                  Checked='&lt;%# Bind("IsTransfer") %&gt;' /&gt;
                              &lt;br /&gt;
                              Prefix:
                              &lt;asp:TextBox ID="PrefixTextBox" runat="server" Text='&lt;%# Bind("Prefix") %&gt;' /&gt;
                              &lt;br /&gt;
                              Number:
                              &lt;asp:TextBox ID="NumberTextBox" runat="server" Text='&lt;%# Bind("Number") %&gt;' /&gt;
                              &lt;br /&gt;
                              Section:
                              &lt;asp:TextBox ID="SectionTextBox" runat="server" 
                                  Text='&lt;%# Bind("Section") %&gt;' /&gt;
                              &lt;br /&gt;
                              ID:
                              &lt;asp:TextBox ID="IDTextBox" runat="server" Text='&lt;%# Bind("ID") %&gt;' /&gt;
                              &lt;br /&gt;
                              &lt;asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                  Text="Insert" /&gt;
                              &amp;nbsp;&lt;asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                                  CommandName="Cancel" Text="Cancel" /&gt;
                          &lt;/InsertItemTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;table style="width:100%;"&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          Prefix:&lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:Label ID="PrefixLabel" runat="server" Text='&lt;%# Bind("Prefix") %&gt;' /&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          Number:&lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:Label ID="NumberLabel" runat="server" Text='&lt;%# Bind("Number") %&gt;' /&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          ClassSection:&lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:Label ID="ClassSectionLabel" runat="server" 
                                              Text='&lt;%# Bind("ClassSection") %&gt;' /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          IsTransfer:&lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:CheckBox ID="IsTransferCheckBox" runat="server" 
                                              Checked='&lt;%# Bind("IsTransfer") %&gt;' Enabled="false" /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/table&gt;
                              &lt;asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                                  Text="Edit" /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:FormView&gt;
  </code></pre>
  
  <p>with a SqlDataSource:</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDSStudentClass" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ReinstatementCS %&gt;"
  
                          DeleteCommand="DELETE FROM [StudentClass] WHERE [SLN] = @SLN" 
                          InsertCommand="INSERT INTO [StudentClass] ([SLN],[ID]) VALUES (@SLN, @ID)"
                          SelectCommand="SELECT DISTINCT Classes.Number, Classes.Section, StudentClass.ID
  FROM 
      StudentClass 
      LEFT JOIN AccessList ON AccessList.ALID = StudentClass.ID
      JOIN Classes ON StudentClass.SLN = Classes.SLN
  WHERE ([SLN] = @SLN)" 
      &lt;!--AccessList just gives extra information to the user--&gt;                    
                          UpdateCommand="UPDATE [StudentClass] SET [SLN] = @SLN, [ID] = @ID WHERE [SLN] = @SLN"&gt;
  
                          &lt;DeleteParameters&gt;
                              &lt;asp:Parameter Name="SLN" Type="Int32" /&gt;
                          &lt;/DeleteParameters&gt;
                          &lt;InsertParameters&gt;
                              &lt;asp:Parameter Name="SLN" Type="String" /&gt;
                              &lt;asp:Parameter Name="ID" Type="String" /&gt;
                          &lt;/InsertParameters&gt;
                          &lt;SelectParameters&gt;
                              &lt;asp:QueryStringParameter Name="ID" QueryStringField="ALID" 
                                  Type="String" /&gt;
                          &lt;/SelectParameters&gt;
                          &lt;UpdateParameters&gt;
                              &lt;asp:Parameter Name="ID" Type="String" /&gt;
                              &lt;asp:Parameter Name="SLN" Type="Int32" /&gt;
                          &lt;/UpdateParameters&gt;
                      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Example of the form in action using the example tables above:</p>
  
  <pre><code>Number Drop Down:
  210                -&gt;   select 210     
  340  
  
  Section Drop Down:
  1
  2                  -&gt; select 3
  3
  </code></pre>