I have a Gridview in which I have made a column of checkboxes named 'Status'. When the user clicks a button I want to see if a checkbox in particular row was checked by him or not. Code I have written is:

for (int i = 0; i <= Grid.Rows.Count; i++)
        {
            if (if checkbox is checked)
                d = m.Mark(Grid.Rows[i].Cells[1].Text, Date.Text, 'P');
            else
                d = m.Mark(Grid.Rows[i].Cells[1].Text, Date.Text, 'A');
        }

What code should I write in (if checkbox is checked) so that I can get the desired result?

Recommended Answers

All 2 Replies

You will need to know the ID (name) of your CheckBox.
I called mine "cb1".

private void button1_Click(object sender, EventArgs e)
      {
         CheckBox cb = (CheckBox)dataGridView1.Controls["cb1"];
         if (cb.Checked)
         {
            MessageBox.Show("Checked");
         }
         else
         {
            MessageBox.Show("NOT Checked");
         }
      }

Thank you for replying to my question. I got the way to make it work. I had written code similar to what you have given here. What I was doing wrong was that I was not binding data to gridview in PreRender function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.