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
------解决方案--------------------
------解决方案--------------------DropDownList1.Selecteditem.value.ToString();
------解决方案--------------------那你只能用ajax了
不刷新当然不可能实现绑定了
------解决方案--------------------AJAX
只能这样了
------解决方案--------------------
------解决方案--------------------ajax了
------解决方案--------------------用ajax实现