Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

populating drop down list using EF6

$
0
0

I am trying to upgrade my site to asp.net.identity, but having problems almost every step. I have a simple drop down that just displays a list of states for the user to select from. There are several  post on how to do this.

  1. add dropdown to form w autopostback= true
  2. Add new class library and delete the class1.cs from lib
  3.  Add a new ADO.Net Entity Data model to the class library project. 
  4. name it appropriately (statelist.edmx)
  5. in Wizard select > Generate from Database and select States table
  6. finish Wizard.

This creates the edmx file, a several other files context, diagram, etc, and lastly a state dataset that contains all of the column names. But nowhere is there a ctx.

The code for the page that has the drop down is:

try
  {
  if (!IsPostBack)
  {
  using (var ctx = new CompanyEmployeesEntities())
  {

  var companies = from comp in ctx.Companies
      where comp.CompanyName.StartsWith("Ad")
      orderby comp.CompanyName
      select new { comp.CompanyID, comp.CompanyName };

     DropDownList1.DataValueField = "CompanyID";
     DropDownList1.DataTextField = "CompanyName";
     DropDownList1.DataSource = companies;
     DataBind();


     }

   }
 }


 catch (Exception ex)
 {

 Response.Write(ex.Message);
 }

Since the ctx is not there the code errors I have had the same problem with two posts.

I am using VS2015, EF6 and aspnet.identity. I think the code in the posts may be EF4?

 


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>