前台: <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 + ";"; } }
|