How do I display Country and City information like below?

  • India
    • Delhi
    • Bangalore
    • Chennai
  • USA
    • New York
    • Chicago
  • UK
    • London

For this example, we will use GridView and ObjectDataSource.

The CityHelper class fetches data from database. Fill a collection of countries. And within each country, fill a collection of cities.

// Class used by ObjectDataSource
// Fetches data from database
// Puts the data as list of countries with list of cities within
public class CityHelper
{
    private Dictionary<Country, List<City>> cities = new Dictionary<Country,List<City>>();

    public CityHelper()
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Pubs"].ConnectionString);
Read More