How, I am trying to bind my 2 of my dropdownlist based on a ProductID and it's available size and available color hence if a user selects say grey, only sizes available for grey will appear and vice versa for the size. I am trying the below linq statement below, apparently it throws a "LINQ to Entities does not recognize the method 'System.String ToString()' method", I am not sure if the linq construction is right either. Can anyone please advice? Thanks.
if (!Page.IsPostBack)
{
using (CommerceEntities db = new CommerceEntities())
{
int tempNum; // ----> The ProductId
if (Int32.TryParse(litTypeSel.Text, out tempNum))
{
if ((ddlColor.SelectedValue == "") && (ddlSize.SelectedValue == ""))
{
ddlColor.DataSource = (from p in db.ProductTypes
where p.ProductID == tempNum && (p.Size == (from s in db.ProductTypes select s.Size).ToString())
orderby p.Color
select new { p.Color }).Distinct();
ddlColor.DataTextField = "Color";
ddlColor.DataBind();
ddlColor.Items.Insert(0, new ListItem("Select Color", "NA"));
ddlSize.DataSource = (from p in db.ProductTypes
where p.ProductID == tempNum && (p.Color == (from c in db.ProductTypes select c.Color).ToString())
orderby p.Size descending
select new { p.Size }).Distinct();
ddlSize.DataTextField = "Size";
ddlSize.DataBind();
ddlSize.Items.Insert(0, new ListItem("Select Size", "NA"));
}
}
}
}