asp.net2级联动
我的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cate_bind();
}
}
public void cate_bind()
{
string str1 ="select * from sheng";
SqlDataAdapter adp = new SqlDataAdapter(str1,conn);
DataSet ds = new DataSet();
adp.Fill(ds,"yj");
DropDownList1.DataSource=ds.Tables["yj"];
DropDownList1.DataValueField ="id";
DropDownList1.DataTextField ="type";
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string str1 = "select * from sheng2 where t_id="+ DropDownList1.SelectedValue.ToString();
SqlDataAdapter adp = new SqlDataAdapter(str1, conn);
DataSet ds = new DataSet();
adp.Fill(ds, "yj");
DropDownList2.DataSource = ds.Tables["yj"];
DropDownList2.DataValueField ="t_id";
DropDownList2.DataTextField ="type";
DropDownList2.DataBind();
}
这个DropDownList1能显示出来,这个DropDownList2不能显示出来值。
[解决办法]
DropDownList1的属性autopostBACK要为TRUE
[解决办法]