dropdownlist联动 用事件做
Brand--汽车品牌表BID主键,自动增长,汽车品牌编号BName汽车品牌-----------------------------------------------...
Brand--汽车品牌表
BID 主键,自动增长,汽车品牌编号
BName 汽车品牌
------------------------------------------------------
Types--汽车型号表
TID 主键,自动增长,汽车型号编号
TName 汽车型号
BID 外键,与Brand表关联,
后台代码
public void DropDown1()
{
string sql = "select distinct(BName) from Brand";
DataTable data =(DataTable) BrandManager.lianDong(sql);
DropDownList1.DataTextField = "BName";
DropDownList1.DataValueField = "BName";
DropDownList1.DataSource = data;
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "select TName from Types T inner join Brand B on T.BID=B.BID where B.BName='" + DropDownList1.Text + "'";
DataTable data = (DataTable)BrandManager.lianDong(sql);
DropDownList2.DataTextField = "TName";
DropDownList2.DataValueField = "TName";
DropDownList2.DataSource = data;
DropDownList2.DataBind();
}
DropDownList1的值可以正常显示,就是DropDownList2不显示
我设断点调试过了,执行完DropDown1()这个方法后,不执行DropDownList1_SelectedIndexChanged!
SQL语句在SQL server 数据库中运行正常!
请高手帮帮忙!!! 展开
BID 主键,自动增长,汽车品牌编号
BName 汽车品牌
------------------------------------------------------
Types--汽车型号表
TID 主键,自动增长,汽车型号编号
TName 汽车型号
BID 外键,与Brand表关联,
后台代码
public void DropDown1()
{
string sql = "select distinct(BName) from Brand";
DataTable data =(DataTable) BrandManager.lianDong(sql);
DropDownList1.DataTextField = "BName";
DropDownList1.DataValueField = "BName";
DropDownList1.DataSource = data;
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "select TName from Types T inner join Brand B on T.BID=B.BID where B.BName='" + DropDownList1.Text + "'";
DataTable data = (DataTable)BrandManager.lianDong(sql);
DropDownList2.DataTextField = "TName";
DropDownList2.DataValueField = "TName";
DropDownList2.DataSource = data;
DropDownList2.DataBind();
}
DropDownList1的值可以正常显示,就是DropDownList2不显示
我设断点调试过了,执行完DropDown1()这个方法后,不执行DropDownList1_SelectedIndexChanged!
SQL语句在SQL server 数据库中运行正常!
请高手帮帮忙!!! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询