Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear friends,

I am getting cities from webservice in the following url: [^]

Its executed. but can i change values. for Eg. in that cities list have Madras. I need to change madras as chennai and change order of the cities. Is it possible to change.

What I have tried:

getting city:

net.webservicex.www.GlobalWeather we = new net.webservicex.www.GlobalWeather();
            string country = ddlCountry.SelectedValue.ToString();
            string city = we.GetCitiesByCountry(country);
            var cities = XDocument.Parse(city).Descendants("City").Select(arg => arg.Value).ToList();
            ddlCity.DataSource = cities; 
            ddlCity.DataBind();        
Posted
Updated 27-Oct-17 0:12am
v2

1 solution

you shall modify the collection once you get the data from the service

List<string> lstCities = new List<string>();

foreach (string city in cities)
{
   string _city = city;
    if(city == "Madras")
        _city = "Chennai";
   lstCities.add(_city);
     
}


 ddlCity.DataSource = lstCities ;
            ddlCity.DataBind();  
 
Share this answer
 
Comments
Vivek.anand34 27-Oct-17 6:36am    
S working fine.. but how to change order.. can i change order of the cities..
it showing not asc or desc all mixed.
Karthik_Mahalingam 27-Oct-17 7:16am    
lstCities = lstCities.OrderBy(k => k).ToList();
Vivek.anand34 27-Oct-17 8:02am    
Thank you. its working.. am using this
lstCities.Sort();
Karthik_Mahalingam 27-Oct-17 8:02am    
Good

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900