title: Implementing cascading DropDownList binding in a templated control
body: <p>I have 2 <code>DropDownList</code> controls on my form, the second of which uses the <code>SelectedValue</code> of the first as one of its binding parameters.</p>
  
  <p>Both <code>DropDownList</code> controls are in a <code>FormView.InsertItemTemplate</code> with <code>SelectedValue</code> properties bound to the <code>FormView</code>'s datasource using a Binding Expression.  </p>
  
  <p>The first time the <code>FormView</code> renders in Insert mode, everything works fine.  The problem is after an <code>AutoPostBack</code> from the first <code>DropDownList</code>, the <code>FormView</code> doesn't (re-)bind, however since the <code>ControlParameter</code> on the second <code>DropDownList</code> has changed, it DOES bind (as intended), but an exception occurs on the Binding Expression of the second DDL, I assume since the <code>FormView</code> is not binding on that pass:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: Databinding methods such as Eval(),
    XPath(), and Bind() can only be used in the context of a databound
    control.</p>
  </blockquote>
  
  <p>Here is the markup:</p>
  
  <pre><code>&lt;InsertItemTemplate&gt;
  .
  .
  .
  &lt;tr class="GridViewRowB"&gt;
                      &lt;td class="GridViewCell"&gt;
                          Offense Type
                      &lt;/td&gt;
                      &lt;td class="GridViewCell"&gt;
                          &lt;asp:DropDownList ID="ddlOffenseType" runat="server" DataSourceID="dsOffenseType"
                              AutoPostBack="true" DataValueField="OffenseTypeID" DataTextField="Description"
                              SelectedValue='&lt;%# Bind("OffenseTypeID") %&gt;'&gt;
                          &lt;/asp:DropDownList&gt;
                          &lt;asp:ObjectDataSource ID="dsOffenseType" runat="server" TypeName="OffenseType"
                              SelectMethod="GetAll"&gt;
                              &lt;SelectParameters&gt;
                                  &lt;asp:Parameter Name="ActiveOnly" DefaultValue="True" Type="Boolean" /&gt;
                              &lt;/SelectParameters&gt;
                          &lt;/asp:ObjectDataSource&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr class="GridViewRowA"&gt;
                      &lt;td class="GridViewCell"&gt;
                          Attorney
                      &lt;/td&gt;
                      &lt;td class="GridViewCell"&gt;
                          &lt;asp:DropDownList ID="ddlAttorney" runat="server" DataSourceID="dsAttorney" DataValueField="AttorneyID"
                              DataTextField="AttorneyNameWithCount" SelectedValue='&lt;%# Bind("AttorneyID") %&gt;'&gt;
                          &lt;/asp:DropDownList&gt;
                          &lt;asp:ObjectDataSource ID="dsAttorney" runat="server" TypeName="Attorney"
                              SelectMethod="GetAttorneyWithCaseCount"&gt;
                              &lt;SelectParameters&gt;
                                  &lt;asp:Parameter Name="ActiveOnly" DefaultValue="True" Type="Boolean" /&gt;
                                  &lt;asp:ControlParameter Name="OffenseTypeID" Type="Int32" ControlID="ddlOffenseType"
                                      PropertyName="SelectedValue" /&gt;
                              &lt;/SelectParameters&gt;
                          &lt;/asp:ObjectDataSource&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
  .
  .
  .
  &lt;/InsertItemTemplate&gt;
  </code></pre>
  
  <p>My question is:  What is the best way to make this functionality work?  Is it possible to keep both DDL's inside the template?  I would prefer to avoid using the AJAX toolkit or other client-side solutions.</p>