I am having this function which will return list of cities based on the state.Here is the function.
public IList<string> GetCity(int index)
{
using (var db = new DataClasses1DataContext())
{
var city = db.mem_cities.Where(c => c.state_id.Equals(index)).Select(c => c.city_name).ToList();
return city;
}
}
Now I call this function from my code behind like this.
var city = CustomerBLL.GetCity(index);
CustomerBLL is my class
Now I want to fill my DropDownList with the cities returned.
So I do something like this.
ddlCity.DataSource = city;
ddlCity.DataBind();
This works fine.Earlier I tried using foreach loop
foreach (var c in city)
{
ddlCity.Items.Add(c.city);
}
But it gave an error
string does not contain a definition for string
So my question is suppose if I wanted to iterate through the List what should I return from the function.
Can someone point me where I am going wrong?
Return not a city names (City.Name) but cities themselves: