Question
I am new to .Net Dynamics and using Simple.Data for the first time in a tiny project. I need to query data and assign the records returned to a DropDownList but I get a list of "Simple.Data.SimpleQuery" items in my ddl. The code snippet is below.
var show_crm = Database.Open();
var sites = show_crm.tblSites.Select(show_crm.tblSites.SiteID, show_crm.tblSites.SiteName);
DropDownList1.DataSource = sites;
DropDownList1.DataValueField = sites.SiteID;
DropDownList1.DataTextField = sites.SiteName;
DropDownList1.DataBind();
Please help.
Solution
.Select just creates a query, you need to run it by calling ToList(). Also, you probably need to set the DataValueField and DataTextField properties to the names of the properties.
var show_crm = Database.Open();
var sites = show_crm.tblSites.Select(show_crm.tblSites.SiteID, show_crm.tblSites.SiteName);
DropDownList1.DataSource = sites.ToList<Site>();
DropDownList1.DataValueField = "SiteID";
DropDownList1.DataTextField = "SiteName";
DropDownList1.DataBind();
I've never used Simple.Data in a Web Forms project, so I am not 100% sure the data binding will work with the dynamic properties. If you still have a problem, please comment on this answer.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow