Dropdownlist Datasource by LINQ Query

asp.net c# entity-framework linq

Popular Answer

You get readyquery but never put it to use.

var orders = from order in context.Cities
             where order.CityID == slct
             select order.CityName;

List<Entity.City> lstSrc = orders.ToList();

Edit

Additionally, you must take additional measures.CityName from your remark

var orders = from order in context.Cities
             where order.CityID == slct
             select new { order.CityID, order.CityName };

The returned anonymous type has the following two properties:CityID and CityName However, since it's an anonymous type, you must usevar while stating yourList<T> variable:

var lstSrc = orders.ToList();

or designate someone specificDataSource property:

ddlCity.DataSource = orders.ToList();
3
9/7/2013 4:48:26 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