I need a very simple example of code to populate a DropDownList using Entity Framework 4.
At the moment I use this code:
using (TestHierarchyEntities context = new TestHierarchyEntities())
{
uxSelectNodeDestinationDisplayer.DataSource = context.CmsCategories.ToList();
uxSelectNodeDestinationDisplayer.DataBind();
}
But it does not work properly... Any idea? Thanks
Something like this should work :
using (TestHierarchyEntities context = new TestHierarchyEntities())
{
var category = (from c in context.context
select new { c.ID, c.Desc }).ToList();
DropDownList1.DataValueField = "MID";
DropDownList1.DataTextField = "MDesc";
DropDownList1.DataSource = category;
DropDownList1.DataBind();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With