var metroquery = (from metro in objCommon.Lst_Cities
where (SqlMethods.Like(metro.CityNM, "Mumbai") ||
SqlMethods.Like(metro.CityNM, "Delhi" )||
SqlMethods.Like(metro.CityNM, "Kolkata") ||
SqlMethods.Like(metro.CityNM, "Chennai") ||
SqlMethods.Like(metro.CityNM, "Bangalore") ||
SqlMethods.Like(metro.CityNM, "Pune") ||
SqlMethods.Like(metro.CityNM ,"Ahmedabad") ||
SqlMethods.Like(metro.CityNM , "Hyderbad"))
select metro).ToList();
var nonmetroquery = (from metro in objCommon.Lst_Cities
where !metro.CityNM.Contains("Mumbai") &&
!metro.CityNM.Contains("Delhi") &&
!metro.CityNM.Contains("Kolkata") &&
!metro.CityNM.Contains("Chennai") &&
!metro.CityNM.Contains("Bangalore") &&
!metro.CityNM.Contains("Pune") &&
!metro.CityNM.Contains("Ahmedabad") &&
!metro.CityNM.Contains("Hyderbad")
select metro).ToList();
I have written these two Linq queries to retrieve the cities and add the first order of cities i.e. Mumbai and others at top. Second query contains non-metro cities which I want to append to the combo.
Basically I want metro cities at top and non metro below metro cities.
I have used the following code for this:
List<Lst_City> lstCity1 = new List<Lst_City>();
foreach (var t in metroquery)
{
lstCity1 = metroquery;
}
System.Threading.Thread.Sleep(200);
foreach (var t in nonmetroquery)
{
lstCity1 = nonmetroquery;
}
but I am getting only the non metro cities binded to the ComboBox.
Any help o hint?
In your foreach method, you are adding the whole list instead of
var t.Perhaps this would work: