怎样把两个dropdownlist绑定,当其中一个dropdownlist选择某一项时,另一个相应的显示相关内容。谢谢!!!

解决方案 »

  1.   

    ajax controltoolkit里好像可以支持三个dropdownlist之间的级联。只有两个的话一个UpdatePanel不能搞定吗?
      

  2.   

    首先设置其中一个dropdownlist的autopostback属性为true,
    然后在SelectedIndexChanged事件里面写逻辑
      

  3.   

    把选择的那项id 赋给第二个dropdownlist就是了
      

  4.   


    //很简单  第一个设置为autopostback=ture
    //然后ID关联
      

  5.   

    上级那个dropdownlist你可以用数据源绑定值
    下级那个dropdownlist在页面用代码写SelectedIndexChanged事件
    protected void ddlParentType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //这个是实例业务层信息
            PayTypeManager ptm = new PayTypeManager();        //ddlType是下级列表名,ptm.GetChildPayType,是根据上级列表选中的值查找对应下级列表的值
            this.ddlType.DataSource = ptm.GetChildPayType(Convert.ToInt32((this.ddlParentType.SelectedValue.ToString())));
            if (this.ddlParentType.SelectedIndex == 0)
            {
                this.ddlType.Items.Clear();
            }
            else
            {
                this.ddlType.DataTextField = "PayTypeName";
                this.ddlType.DataValueField = "PayTypeId";
                this.ddlType.DataBind();
            }
        }
      

  6.   

    SelectedIndexChanged && Autopostback="true"
      

  7.   

    你将上一级的ddl的Autopostback属性设置为true
    然后在该ddl中的SelectedIndexChanged 方法中设置另外一个ddl的数据源就行了
      

  8.   

    先获取出第一个dropdownlist的Selectedvalue  然后作为条件去查出数据
    再设置第二个dropdownlist的selectedvalue  为你刚查出的数据
      

  9.   

    这类似于城市三级联动,用jQuery+XML实现很容易,网上也有大把的类子。