471,338 Members | 1,036 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Programmatically adding a column of Checkboxes to Gridview

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.
Jun 27 '08 #1
3 6139
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

--
To be Happy is To be Yourself
"d.***********@gmail.com" wrote:
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.
Jun 27 '08 #2
On Apr 28, 10:50*pm, d.s.steven...@gmail.com wrote:
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
Jun 27 '08 #3
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?
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Wayne Deleer | last post: by
5 posts views Thread by NKaufman | last post: by
reply views Thread by =?Utf-8?B?SlA=?= | last post: by
3 posts views Thread by =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post: by
2 posts views Thread by John Straumann | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.