Qaiser Mehmood

Qaiser Mehmood

  • NA
  • 105
  • 0

populate 2nd dropdownlist on first dropdown selectedindexchange

Feb 25 2009 4:47 AM

 how to populate 2nd dropdownlist on first dropdown selectedindexchange using data base please any help or code 

Thanks in advance, in my code after postback  the previus vlaus added in new selected region;

protected void Page_Load(object sender, EventArgs e)

{ if (!IsPostBack)

{ddlPickUp.Enabled = false;

ddlDropOf.Enabled = false;

string connString = ConfigurationManager.ConnectionStrings["AUTODIRECT"].ConnectionString;

OleDbConnection conn = new OleDbConnection(connString);

conn.Open();

OleDbCommand objcomand = new OleDbCommand("select * from Location", conn);

OleDbDataReader rd = objcomand.ExecuteReader();

while (rd.Read() == true)

{

dlRegion.DataSource = rd;

dlRegion.DataValueField = "id";

dlRegion.DataTextField = "pickup_location";

dlRegion.DataBind();

}

conn.Close();

}

}

..............................................................................................

protected void dlRegion_SelectedIndexChanged(object sender, EventArgs e)

{ if (dlRegion.SelectedIndex != 0)

{ ddlPickUp.Enabled = true;

string connString1 = ConfigurationManager.ConnectionStrings["AUTODIRECT"].ConnectionString;

OleDbConnection conn1 = new OleDbConnection(connString1);

conn1.Open();

OleDbCommand objcomand1 = new OleDbCommand("select * from Place", conn1);

OleDbDataReader rd1 = objcomand1.ExecuteReader();

while (rd1.Read() == true)

{

ddlPickUp.DataSource = rd1;

ddlPickUp.DataValueField = "id";

ddlPickUp.DataTextField = "Area";

ddlPickUp.DataBind();

}

conn1.Close();

 


Answers (6)