public void sort(string aad)//绑定大品种
    {
        this.DropDownList2.Items.Clear();
        string sql = "select * from sort where sid=" + Convert.ToInt32(aad) + " order by paixu";
        DataSet ds = DB.dss(sql);
        
        this.CheckBoxList1.DataSource = ds.Tables[0];
        this.CheckBoxList1.DataTextField = "aname";//绑定的字段名
        this.CheckBoxList1.DataValueField = "aname";//绑定的值
        this.CheckBoxList1.DataBind();
        if (ds.Tables[0].Rows.Count != 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                this.DropDownList2.Items.Add(new ListItem(ds.Tables[0].Rows[i]["aname"].ToString(), ds.Tables[0].Rows[i]["aname"].ToString()));
            }
        }
        else
        {
            this.DropDownList2.Items.Add(new ListItem("没有任何分类", ""));
        }
    }
 protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)//大品种选项改变
    {
     
        string save_cblJL = "";
        for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
        {
            if (this.CheckBoxList1.Items[i].Selected == true)
            {
                save_cblJL += this.CheckBoxList1.Items[i].Value + ",";
            }
        }
       
        Response.Write(save_cblJL);
        this.Label9.Text = save_cblJL;
    }
相关表
sort :aid(主键) sid aname
lisort : id(主键) aid  name 
要求:CheckBoxList1选项变化时 根据选中的项的aid  从lisort表中选出所有lisort.aid=sort.aid的项  动态生成新的复选框 
请各位高手帮帮忙   在这里谢谢了  

解决方案 »

  1.   

    你现在要的这个功能 其实你在上面就已经写过了 就像你动态添加DropDownList2的item一个意思,你把CheckBoxList1的value作为参数去数据库中查询出所有lisort.aid=sort.aid的项 用个循环 添加到复选框就行了
      

  2.   

    this.CheckBoxList1.DataValueField = "aid";
    "select * from isortwhere aid='"+this.CheckBoxList1.Items[i].Value +"'"
    CheckBoxList   checkbox   =   new   CheckBoxList(); 
    this.Controls.Add(checkbox);
      

  3.   

     protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string save_cblJL = "";
            for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
            {
                if (this.CheckBoxList1.Items[i].Selected == true)
                {
                   string sql1= "select * from lisort where aid='" + this.CheckBoxList1.Items[i].Value + "'";
                   DataSet ds = DB.dss(sql1);
                   for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                   {
                       this.CheckBoxList2.Items.Add(        new ListItem(ds.Tables[0].Rows[j]["name"].ToString(), ds.Tables[0].Rows[j]["id"].ToString()));    
                   }
                       save_cblJL += this.CheckBoxList1.Items[i].Value + ",";
                }
            }
           
            Response.Write(save_cblJL);
            this.Label9.Text = save_cblJL;
        }谢谢上面几位朋友    已经可以动态生成新的复选框了    但是怎么在CheckBoxList1_SelectedIndexChanged的时候清空之前生成的复选框呢