日期:2014-05-17  浏览次数:20428 次

DropDownList多级,清空数据
C# code


    private void getName()
    {
      
            this.DropDownList1.DataSource =DropDownList1();
            this.DropDownList1.DataValueField = "id";
            this.DropDownList1.DataTextField = "name";
            this.DropDownList1.DataBind();
            this.DropDownList1.Items.Insert(0, new ListItem("--请选择--", "0"));
            this.DropDownList2.Items.Insert(0, new ListItem("--请选择--", "0"));
            this.DropDownList3.Items.Insert(0, new ListItem("--请选择--", "0"));


      
    }
//点击第一级获得第二级数据
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
          string id = this.DropDownList1.SelectedValue;

            this.DropDownList2.DataSource =GetDropDownList2(id);
            this.DropDownList2.DataValueField = "id";
            this.DropDownList2.DataTextField = "name";
            this.DropDownList2.DataBind();
            this.DropDownList3.Items.Insert(0, new ListItem("--请选择--", "0"));   

    }
//点击第二级获得第三级数据
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {

            string id = this.DropDownList2.SelectedValue;
            this.DropDownList3.DataSource = GetDropDownList3(id);
            this.DropDownList3.DataTextField = "name";
            this.DropDownList3.DataValueField = "id";
            this.DropDownList3.DataBind();
            this.DropDownList3.Items.Insert(0, new ListItem("--请选择--", "0"));

       
    }




目前重新选择的话第三级的数据还是之前选择第二级所获得的数据
请问重新点击第一级的时候 如何清空第三级的数据 显示--请选择--?



------解决方案--------------------
在选择第一级的时候dropdownlist3.Items.Clear();