C# 如何在C中基于数据库值检查复选框#

C# 如何在C中基于数据库值检查复选框#,c#,asp.net,checkbox,checkboxlist,C#,Asp.net,Checkbox,Checkboxlist,我已经创建了复选框列表和按钮,以使用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"

我已经创建了复选框列表和按钮,以使用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"/>
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);
}
}
然后单击按钮事件将所选值存储在数据库中,如下所示:

 <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"/>
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);
}
}
现在,我有另一个按钮来编辑复选框列表选择。现在,我想从数据库中检索数据,并在单击编辑按钮时选中数据库中可用的复选框(单击保存按钮时在数据库中插入复选框值)。

请尝试:

for each (DataRow row in resultTable.Rows)
{
    if (Convert.ToBoolean(row["bit_column_name"]))
    {
         // check box is "1" (checked) in the database
         .....
    }
}

谢谢你的回复。我已经在你的回复帮助下找到了答案。