Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:57:15+00:00 2026-06-12T14:57:15+00:00

I am new to ASP.NET and currently having problem with dropdownlists in the DetailsView.

  • 0

I am new to ASP.NET and currently having problem with dropdownlists in the DetailsView.

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

I have this code my code behind to refresh the list for the dropdownlists in DetailsView

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; 
    } 
}

These two dropdownlists in the DetailsView

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

    <asp:SqlDataSource ID="VendorSqlDataSource"
        ConnectionString="<%$Connectionstrings:ConnectionString%>" 
        SelectCommand="SELECT VendorID, VendorName from MDF_Vendor"
        runat="server"> 
    </asp:SqlDataSource> 
</EditItemTemplate> 


<EditItemTemplate>
    <asp:DropDownList id="VendorBUName"
        datasourceid="VendorBUSqlDataSource" 
        datatextfield="VendorBUName"
        DataValueField="VendorBUID"   
        SelectedValue='<%# Bind("VendorBUID") %>'  
        runat="server"/>

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

Problem is:

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()… “.

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.

Can someone please let me know what wrong in my codes? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:57:16+00:00Added an answer on June 12, 2026 at 2:57 pm

    As the error states, you cannot use Bind where you are trying to use it. You should be able to use the DataBinder though

    SelectedValue='<%# DataBinder.Eval (Container.DataItem, "VendorBUID") %>'
    

    Edit: Since binding a value to the SelectedValue with DataBinder didn’t work, you can try to set the value when binding data. Provided dataSource is some instance of a class that has a property called VendorBUID, something similar to this might work in

    public override void OnLoad(EventArgs e) {
        VendorBUName.DataBinding += dataBindDropDown;
    }
    
    private void dataBindDropDown(object sender, EventArgs e) {
        VendorBUName.SelectedValue = dataSource.VendorBUID;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently going through the ASP.NET MVC NerdDinner tutorial and am having a problem
I am still new to asp.net and I'm having a problem that I just
I'm having a problem passing cookies in ASP.NET to a new URL. I add
Im currently new to PHP and JQuery after having using ASP.Net and C Sharp
I am new to Entity Framework. I am currently doing a project in ASP.NET,
I'm having a serious problem with my ASP.NET AJAX application. There is a javascript
I'm new to Asp.net and I'm currently working with GridViews. I've looked around this
Hello i am currently developing a ASP.NET MVC 3 application that uses the new
I'm having a small problem with ASP.NET MVC and Entity Framework 4. I have
I'm having a problem trying to get routing to work with ASP.NET MVC 3.0.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.