Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 SQL Statement

Author  Topic 

lala
Starting Member

1 Post

Posted - 2009-09-30 : 02:37:20
Hi,

I want to display some values from DropDownList A based on selected values in DropDownList B. However, there's no common column names in the 2 tables I'm going to take datas from. How can I go about it?


string strCon2 = Database.GetConStr();
SqlConnection sqlCon2 = new SqlConnection(strCon2);
try
{ //bind the B dropdownlist
string strSql2 = "SELECT D, P FROM Apple WHERE P = 'B' AND Status = 'Available' ORDER BY D";
SqlCommand sqlCmd2 = new SqlCommand(strSql2, sqlCon2);
sqlCon2.Open();
SqlDataReader reader2 = sqlCmd2.ExecuteReader();
while (reader2.Read())
{
ddlB.Items.Add(new ListItem(reader2["D"].ToString(), reader2["P"].ToString()));
}
reader2.Close();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
finally
{
sqlCon2.Close();
}



protected void ddlB_SelectedIndexChanged(object sender, EventArgs e)
{
ddlA.Items.Clear(); //upon selected B, refresh A
ddlA.Items.Add(new ListItem("All", "%"));
string strCon5 = Database.GetConStr();
SqlConnection sqlCon5 = new SqlConnection(strCon5);
try
{ //bind the A dropdownlist
string strSql5 = "SELECT C, D, FROM Orange";

SqlCommand sqlCmd5 = new SqlCommand(strSql5, sqlCon5);
sqlCmd5.Parameters.AddWithValue("@B", ddlB.SelectedValue);
sqlCon5.Open();
SqlDataReader reader5 = sqlCmd5.ExecuteReader();
while (reader5.Read())
{
ddlA.Items.Add(new ListItem(reader5["C"].ToString(), reader5["D"].ToString()));
}
reader5.Close();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
finally
{
sqlCon5.Close();
}

}
   

- Advertisement -