Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m generating datagridviewcheckboxcolumn in run time but i don't know how can i check
it's checked property true or false....

plz any one help me...(In Windows Application)

thanks in advance.....
Posted
Updated 22-Apr-16 2:10am
v2

C#
foreach (DataGridViewRow dataGridRow in dataGridView1.Rows)
{
   if (dataGridRow.Cells["YourCheckboxColumn"].Value != null &&    (bool)dataGridRow.Cells["YourCheckboxColumn"].Value)
  {
         // Checked
  }
  else if (dataGridRow.Cells["YourCheckboxColumn"].Value == null)
  {
         // Unchecked
  }
}


:)
Regard
Sham
 
Share this answer
 
Comments
adyashreeswain 5-Jun-13 7:42am    
thanx alot sham
Shambhoo kumar 8-Jul-15 3:35am    
you are welcome dear.
Try this, It may help you:-

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox chk = (CheckBox)(e.Row.FindControl("CheckBoxId"));

            If(chk.Text == "MyName")
             {
               chk.Checked = true;
             }
        }
 
Share this answer
 
Comments
Shambhoo kumar 12-Sep-12 3:55am    
i want to check on button click event...
If you want to check in button click event then cod eshould be like this:-

C#
for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");

                if (chk.Checked)
                {
                   //your logic
                }

         }


Here in Cells[index], your index is the position of your checkbox column location.

Hope you find your solution.
Fun coding....
 
Share this answer
 
v2
Comments
Member 14836421 22-May-20 1:10am    
Hi. i don't find "Findcontrol" in My Code? Please help me !!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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