7b. Create a web application for to display the phone no of an author using database.

Program:



Create a web application for to display the Postal Code no of Customer using database.

Create a web page with DropDownList, Button and with Label control as shown below.











Code of C# Code behind file

using System;

using System.Collections.Generic;
using System.Linq;

using System.Web;

using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

public partial class PostalCodeByCity : System.Web.UI.Page

{


protected void Button1_Click(object sender, EventArgs e)
{

Label1.Text = ListBox1.SelectedValue;

}

protected void Page_Load(object sender, EventArgs e)

{
if (IsPostBack == false)

{

string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;

SqlConnection con = new SqlConnection(connStr);

SqlCommand cmd = new SqlCommand("Select Distinct POSTAL_CODE from Customer",
con);

con.Open();



SqlDataReader reader = cmd.ExecuteReader();
ListBox1.DataSource = reader;

ListBox1.DataTextField = "City";

ListBox1.DataValueField = "POSTAL_CODE";
ListBox1.DataBind();

reader.Close();

con.Close();

}

}

}



Comments