Programmatically adding a column of Checkboxes to Gridview

  • Thread starter Thread starter d.s.stevenson
  • Start date Start date
D

d.s.stevenson

Hi,

Could someone please help me with sample code on how to
programmatically add a column of checkboxes to data displayed in a
Gridview? And how to find whether the checkbox is checked or not on
postback.

Thanks in advance.
 
hi and hello good day.

you can try this codes:

//declare it to the top
DataGridViewCheckBoxColumn mygrid = new DataGridViewCheckBoxColumn();

private void Form1_Load(object sender, EventArgs e)
{
mygrid.HeaderText = "Status";
mygrid.Name = "status";
grid.Columns.Insert(0, mygrid);
}

private void grid_CellMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
{
if (mygrid.ThreeState == false)
{MessageBox.Show("check");}
else
{MessageBox.Show("uncheck");}
}



I hope it can help u
 
Hi,

Could someone please help me with sample code on how to
programmatically add a column of checkboxes to data displayed in a
Gridview? And how to find whether the checkbox is checked or not on
postback.

Thanks in advance.

Hi,

Take a look at ITemplate
 
Thanks for your help.. I get the following error when i try the code
you supplied.

cannot convert from 'System.Windows.Forms.DataGridViewCheckBoxColumn'
to System.Web.UI.WebControls.DataControlField'

code:

DataGridViewCheckBoxColumn mygrid = new DataGridViewCheckBoxColumn();
mygrid.HeaderText = "Status";
mygrid.Name = "status";
grdAdv.Columns.Insert(0, mygrid); //Error produced on this line.

Any ideas?
 
Back
Top