想通过CheckBoxList实现的功能是,从数据库中取出一共有多少个显示页面,然后每一个页面都拥有一个CheckBoxList,请问如何动态生成多个CheckBoxList呢?

解决方案 »

  1.   

    CheckBoxList x = new CheckBoxList();
    this.form1.Controls.Add(x);
      

  2.   

    如何将读出来的信息循环绑定到CheckBoxList中呢?
      

  3.   

    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
    </asp:CheckBoxList>
    CheckBoxList1.DataSource = "数据源";
            CheckBoxList1.DataTextField = "文本字段";
            CheckBoxList1.DataValueField = "ID字段";
            CheckBoxList1.DataBind();
      

  4.   

    http://apps.hi.baidu.com/share/detail/15644851
      

  5.   

    初学请多帮忙!string sql = "select pagename from page";
    conn = new SqlConnection(Connection.connString);
    SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
    DataSet dataSet = new DataSet();
    conn.Open();
    adapter.Fill(dataSet, "pages");请问如何对dataSet的pages表中的pagename字段,进行checkBoxList,一条记录绑定一个checkBoxList
      

  6.   

    string sql = "select pagename from page";
    conn = new SqlConnection(Connection.connString);
    SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
    datetable dt=new datetable();
    conn.Open();
    adapter.Fill(dt);
    this.CheckBoxList1.DataTextField ="pagename";
    this.CheckBoxList1.DataValueField = "";
    this.CheckBoxList1.datasourse=dt;
    this.CheckBoxList1.databind();
      

  7.   

    conn.open();不需要这个
     SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);直接这个就可以了
      

  8.   


    谢谢哦!我还有一个想法,就是现在能显示出来页的checkBoxList了,可以在找的页的显示的同时,显示页面中的控件吗?并且也用CheckBoxList输出呢?也就是在同一个页面中通过不同的CheckBoxList,一边显示页面,另一边显示页面对应的控件获得页面控件的方法是/// <summary>
        /// 有效遍历asp.net页面所有控件的方法
        /// </summary>
        /// <param name="parent">this</param>
        void IterateThroughChildren(Control parent)
        {
            foreach (Control c in parent.Controls)
            {
                //Label1.Text += c.ID + "|";//示例
                if (c.Controls.Count > 0)       // 判断该控件是否有下属控件。
                {
                         IterateThroughChildren(c);    //递归,访问该控件的下属控件集。            }
            }
        }
      

  9.   

    CheckBoxList.DataSource =ds;
    CheckBoxList.DataTextField = "name";
    CheckBoxList.DataValueField = "id";
    CheckBoxList.DataBind();foreach (ListItem lst in CheckBoxList.Items)
      {
      //lst.Value   
      }