【发布时间】:2017-07-11 00:41:15
【问题描述】:
我已经创建了复选框列表和按钮来使用 C# 在 ASP.Net 应用程序中存储检查值,如下所示,
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="120px">
</asp:CheckBoxList>
<asp:Button ID="AddCheckedData" Height="25px" runat="server" Text="Add Checked Data"
onclick="AddCheckedData_Click"/>
我已将 CheckBoxList 绑定在 Code behind as,
public void bindchecklist()
{
B.SFS_CODE = Convert.ToInt32(TxtHQCode.Text);
B.id = 7; //tblparent AND tblchild
ds8 = A.DATA8(B);
CheckBoxList1.DataSource = ds8.Tables[0];
CheckBoxList1.DataTextField = "EMP_NAME";
CheckBoxList1.DataValueField = "EMP_CODE";
CheckBoxList1.DataBind();
}
以及按钮点击事件将选中的值存储到DataBase中如下,
string selemployee = string.Empty;
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
selemployee = item.Value;
B.id = 8;//insert into DCR_CHECKED
B.Emp_Code = selemployee;
ds8 = A.DATA8(B);
}
}
现在,我有另一个按钮来编辑 CheckBoxList 选择。现在,我想从数据库中检索数据并在单击编辑按钮时检查数据库中可用的复选框(单击保存按钮时在数据库中插入的复选框值)。
【问题讨论】:
标签: c# asp.net checkbox checkboxlist