1

I have created Checkbox list and Button to store Checked Values in ASP.Net application using C# as follows,

 <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"/>

I have binded CheckBoxList in 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();
    }

And the button click event to store the selected values in DataBase as follows,

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);
}
}

Now,i have another button to edit the CheckBoxList Selection.Now,i want to retrieve the data from database and check the checkboxes which are availabe(inserted checkbox values in databse when click save button) in DataBase when Clicking Edit Button.

2 Answers 2

1

Please try:

for each (DataRow row in resultTable.Rows)
{
    if (Convert.ToBoolean(row["bit_column_name"]))
    {
         // check box is "1" (checked) in the database
         .....
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply.i have found answer myself with help of your reply.
0
foreach (DataTable table in ds8.Tables)
                {

                    foreach (DataRow dr in table.Rows)
                    {
                        String S = Convert.ToString(dr["EMP_CODE"].ToString());
                        foreach (ListItem item in CheckBoxList2.Items)
                        {
                            if (S == item.Value)
                            {
                                item.Selected = true;
                            }
                        }
                    }
                }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.