触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > 读数据库到CheckBoxList1及提出CheckBoxList1数据的方法

前台:
<tr>
<td height="20" align="right" class="but">相关部门:</td>
<td height="20" class="but"><asp:CheckBoxList ID="CheckBoxList1" runat="server"
        RepeatDirection="Horizontal"></asp:CheckBoxList></td>
</tr>

后台:
读出数据:
    public void BindData()
    {
        //从配置文件获取数据库连接串
        string strConnection = ConfigurationManager.AppSettings["conStr"];
        SqlConnection conn = new SqlConnection(strConnection);
        conn.Open();
        SqlDataAdapter da1 = new SqlDataAdapter("select * from dept_type", conn);//原来的
        DataSet ds1 = new DataSet();
        da1.Fill(ds1, "tb_role_info");
        CheckBoxList1.DataSource = ds1.Tables["tb_role_info"].DefaultView;
        CheckBoxList1.DataValueField = "sort";
        CheckBoxList1.DataTextField = "type";
        CheckBoxList1.DataBind();
        CheckBoxList1.Dispose();
        conn.Close();
    }

提出CheckBoxList1数据:
         string dept_sele = null;
                for (int i = 0; i < CheckBoxList1.Items.Count; i++)
                {
                    if (CheckBoxList1.Items[i].Selected)
                    {
                        dept_sele += CheckBoxList1.Items[i].Value;
                     //   dept_sele += CheckBoxList1.Items[i].Text ;
                     //   Session["buy"] += CheckBoxList1.Items[i].Text + ";";
                    }
                }


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com