DetailsView DropDownLists
<p>I am new to ASP.NET and currently having problem with dropdownlists in the DetailsView.</p>

<p>Exception error: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.</p>

<p>I have this code my code behind to refresh the list for the dropdownlists in DetailsView</p>

<pre><code>protected void ddlVendor_SelectedIndexChanged 
               (object sender, EventArgs e) 
{ 
    DropDownList ddlVendorBB = 
        (DropDownList)DetailsView1.FindControl("VendorBUName"); 

    if (ddlVendorBB != null) 
    { 
        Response.Write("SelectChanged"); 
        ddlVendorBB.DataBind(); 
    } 
} 

protected void SqlDataSourceProd_Selecting 
    (object sender, SqlDataSourceSelectingEventArgs e) 
{ 
    DropDownList ddlVendor = 
        (DropDownList)DetailsView1.FindControl("VendorName"); 

    if (ddlVendor != null) 
    { 
        e.Command.Parameters["@VendorID"].Value = ddlVendor.SelectedValue; 
    } 
}
</code></pre>

<p>These two dropdownlists in the DetailsView</p>

<pre><code>&lt;EditItemTemplate&gt; 
    &lt;asp:DropDownList id="VendorName"
        datasourceid="VendorSqlDataSource"
        AutoPostBack="true"
        datatextfield="VendorName"
        DataValueField="VendorID"   
        SelectedValue='&lt;%# Bind("VendorID") %&gt;'  
        runat="server"
        OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged" /&gt;

    &lt;asp:SqlDataSource ID="VendorSqlDataSource"
        ConnectionString="&lt;%$Connectionstrings:ConnectionString%&gt;" 
        SelectCommand="SELECT VendorID, VendorName from MDF_Vendor"
        runat="server"&gt; 
    &lt;/asp:SqlDataSource&gt; 
&lt;/EditItemTemplate&gt; 


&lt;EditItemTemplate&gt;
    &lt;asp:DropDownList id="VendorBUName"
        datasourceid="VendorBUSqlDataSource" 
        datatextfield="VendorBUName"
        DataValueField="VendorBUID"   
        SelectedValue='&lt;%# Bind("VendorBUID") %&gt;'  
        runat="server"/&gt;

    &lt;asp:SqlDataSource ID="VendorBUSqlDataSource"
        runat="server"
        ConnectionString="&lt;%$Connectionstrings:ConnectionString%&gt;"
        selectcommand="SELECT VendorBUID, VendorBUName
                       from MDF_VendorBU
                       Where VendorID = @VendorID"
        OnSelecting="SqlDataSourceProd_Selecting"&gt; 
        &lt;SelectParameters&gt; 
            &lt;asp:Parameter Name="VendorID" Type="Int32" /&gt; 
        &lt;/SelectParameters&gt; 
    &lt;/asp:SqlDataSource&gt; 
&lt;/EditItemTemplate&gt;
</code></pre>

<p>Problem is:</p>

<p>If I leave SelectedValue= there, the dropdownlists in Edit mode seletected the correct value in the items listed when I first click Edit, but when I select a new VendorName, it errors "Databining method such as Eval(), Xpath(), and Bind()... ".  </p>

<p>Now, if I removed the Selectedvalued for the dropdownlists, it will work for refreshing the VendorBUName when select a new VendorName, but NOT not selected the default VendorID when I click "Edit".  It just list the VendorName list without selected the current VendorID one. </p>

<p>Can someone please let me know what wrong in my codes?  Thanks!</p>
