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:
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.
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();
}
}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not a problem; glad I was able to help. ;=)
ASKER