Entity Framework 4 is used to populate a DropDownList.

asp.net c# entity-framework

Question

I need a very basic example of Entity Framework 4 code that populates a DropDownList.

I now use the following code:

        using (TestHierarchyEntities context = new TestHierarchyEntities())
        {
            uxSelectNodeDestinationDisplayer.DataSource = context.CmsCategories.ToList();
            uxSelectNodeDestinationDisplayer.DataBind();
        }

But it doesn't operate correctly... Any ideas? Thanks

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

Popular Answer

This kind of stuff ought to 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