发布:2023/6/2 17:28:10作者:管理员 来源:本站 浏览次数:630
前端页面:.aspx
<asp:CheckBoxList ID="ckbdot" runat="server" RepeatDirection="Horizontal" Style=" display: inline-block; vertical-align: middle;" CellPadding="10"></asp:CheckBoxList>
后台处理:.aspx.cs
首先绑定值
例如:
using (DataTable dt = new Bllcccp_keywords().getKeywordsBySql(entityC2)) //CheckBoxList 设置 ,用于绑定数据库中的数据
{
ckbdot.DataSource = dt;
ckbdot.DataTextField = "word"//数据字段word
ckbdot.DataValueField = "id"; //数据字段id 主键
ckbdot.DataBind();
}
获取选中的checkbox,用于插入数据库
string chkSelect = "";
for (int i = 0; i < ckbdot.Items.Count; i++)
{
if (ckbdot.Items[i].Selected == true)
chkSelect += ckbdot.Items[i].Text + ",";
}
编辑checkbox,用于从数据库中读取选中编辑
using (SqlDataReader dr = new Bllcccp_bank_activity().getBank_activityByReader(entityC))
{
if (dr.Read())
{
string _dot = dr["settleNode"].ToString();
string[] dot = _dot.Split(',');
for (int i = 0; i < dot.Length; i++)
{
for (int j = 0; j < ckbdot.Items.Count; j++)
{
if (dot[i] == ckbdot.Items[j].Text)
{
ckbdot.Items[j].Selected = true;
}
}
}
}
}
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4