Choice 1

  • Upload
    sanket

  • View
    214

  • Download
    0

Embed Size (px)

DESCRIPTION

afag

Citation preview

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { SqlConnection cn = null; SqlDataReader dr = null; try { cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\GeetP\Documents\Visual Studio 2010\WebSites\WebSite2\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); SqlCommand cmd = new SqlCommand("Select distinct program from Student_info", cn); cn.Open(); dr = cmd.ExecuteReader(); DropDownList1.Items.Clear(); DropDownList1.Items.Add("Select Program"); DropDownList1.DataSource = dr; DropDownList1.DataTextField = "program"; DropDownList1.DataValueField = "program"; DropDownList1.DataBind(); } catch (Exception ex) { throw ex; } finally { cn.Close(); cn.Dispose(); } } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection cn = null; SqlDataReader dr = null; try { cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\GeetP\Documents\Visual Studio 2010\WebSites\WebSite2\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); SqlCommand cmd = new SqlCommand("Select distinct Department from Student_info where Program='"+DropDownList1.SelectedItem.Value+"'", cn); cn.Open(); dr = cmd.ExecuteReader(); DropDownList2.Items.Clear(); DropDownList2.Items.Add("Select Department"); DropDownList2.DataSource = dr; DropDownList2.DataTextField = "Department"; DropDownList2.DataValueField = "Department"; DropDownList2.DataBind(); } catch (Exception ex) { throw ex; } finally { cn.Close(); cn.Dispose(); } } }