Link to home
Start Free TrialLog in
Avatar of WhyDidntItWork
WhyDidntItWork

asked on

Binding Linq Query to Drop Down List

Hi,

Hi,

New to EF.  I'm trying to bind the results of a linq query to a drop down list.  Here's the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ABC
{
    
    public partial class createDoc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HCLEntities Context = new HCLEntities();

            var query = from p in Context.Equipments
                                             orderby p.Unit
                                             select p.Unit;

            projectDropDownList.DataSource = query;
            projectDropDownList.DataBind();

        }
    }
}

Open in new window


When the code is executed, I get the following message:
Data binding directly to a store query is not supported. Instead populate a DBSet with data, for example by calling Load on the DBSet, and then bind to local data.

Not sure how to fix the error.  Suggestions would be greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WhyDidntItWork
WhyDidntItWork

ASKER

That worked like magic!  Thank you.
Not a problem; glad I was able to help.  ;=)