Entity Framework 4 is used to populate a DropDownList.

asp.net c# entity-framework

Question

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

1
3
1/17/2011 10:31:28 AM

Popular Answer

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();                
         }
7
9/12/2013 1:39:00 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow