protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDowsList1();
}
}
public void DropDowsList1()
{
con.Open();
da = new SqlDataAdapter("select * from Products", con);
da.Fill(ds);
DropDownList1.DataValueField = "ProductID";
DropDownList1.DataTextField = "ProductName";
DropDownList1.DataSource = ds.Tables["Products"];
DropDownList1.DataBind();
}
public void DropDowsList2()
{
con.Open();
da = new SqlDataAdapter("select ProductID,ProductName from Products where ProductID = '" + DropDownList1.Text + "'", con);
da.Fill(ds);
DropDownList2.DataValueField = "ProductID";
DropDownList2.DataTextField = "ProductName";
DropDownList2.DataSource = ds.Tables["Products"];
DropDownList2.DataBind();
}
//改变事件
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDowsList2();
}