<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>
Cities and Customers
File: Default.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page
{
protected void CityButton_Click(object sender, EventArgs e)
{
string connString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
string cmdText = "SELECT DISTINCT country, city FROM customers";
DataTable data = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(cmdText, connString);
adapter.Fill(data);
data.Columns.Add("CityCountry", typeof(string), "city + ' ('+ country + ')'");
CityList.DataTextField = "CityCountry";
CityList.DataSource = data;
CityList.DataBind();
}
}