I am populating states DDL using the country DDL
public static IEnumerable bindcountry()
{
var countries = from c in getdata().Descendants(("country"))
orderby (string)c.Element("name")
select (string)c.Element("name");
return countries;
}
public List<string> GetStatesByCountry(string CountryName)
{
var query = from user in getdata().Descendants("country")
where user.Element("name").Value == CountryName
from t in user.Descendants("text")
select t.Value;
return query.ToList();
}
foreach (var VARIABLE in ProfileMasterDAL.bindcountry())
{
if (VARIABLE.ToString().Contains(DropDownList1.SelectedItem.Text))
{
var query = from row in ProfileMasterDAL.bindcountry()
where row.(ProfileMasterDAL.GetStatesByCountrys(DropDownList1.SelectedItem.Text))
select row;
DropDownList2.DataSource = query;
DropDownList2.DataBind();
}
}
The problem is I am unable to define WHERE clause and equals here I am getting an error:
Could not find an implementation of the query pattern for source type
‘System.Collections.IEnumerable’. ‘Where’ not found. Consider
explicitly specifying the type of the range variable ‘row’.
You say that you are trying to populate a DropDownList with the names of the States for a given Country and it looks like that logic is in your
foreachloop. It also looks like yourforeachloop is doing a lot of unnecessary work.It’s iterating through all the Country names when it really only needs to find one of those country names. It also then iterates again through the country names looking for the states.
You should be able to throw out that entire
foreachloop and instead use this:Your
GetStatesByCountrymethod returns just the states that belong to the passed in Country name, so you should just be able to call that, get the names of just those States, and then assign them to yourDropDownList.