Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code and i want to check the checkbox in my datagridview... Please help me...

C#
if (sdr[6].ToString().Equals("1"))
                {
                    //dataGridView1.Rows[i].Cells["Column8"].Selected = true;
                }
                else
                {
                    //dataGridView1.Rows[i].Cells["Column8"].Selected = false;
                }



i is the counter of row. and sdr[6] is the data from database. what should I do in if.
Posted

Please see my past answer:
how to count checked checkboxes of datagridview in c#?[^].

—SA
 
Share this answer
 
Try this code if you want to check wheather checkBox is selected or not:
C#
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
    {
            GridViewRow row = GridView1.Rows[i];
            CheckBox Ckbox = (CheckBox)row.FindControl("CheckBox2");
            if (Ckbox.Checked)
            {
               //your code for selected checkbox
            }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900