Reputation: 21
I have a Datagridview with first column as checkbox.I have created the checkboxcolumn at design itself.While updating the gridview according to the entries from database, I have to check and uncheck the checkbox programatically not all at a time but only a specific row.Please tell me how can I update check boxes programmatically.
Upvotes: 1
Views: 2768
Reputation: 191
At the time of databinding use this code
CheckBox chkbx= e.Item.FindControl("CheckBox1") as CheckBox;
then you can manipulate chkbx.Checked to true or false based on your values
and similarly it can be used for rest of the checkboxes buttons
Upvotes: 0
Reputation: 1
Check datagrid prerender event, get reference to the checkbox and set value accordingly.
Upvotes: 0
Reputation: 2824
During bind data you need to check it manually if flag is true then set it checked otherwise unchecked as like
set checkbox1.checked=true or false
Upvotes: 0
Reputation: 4663
Do something like this
(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;
Upvotes: 2
Reputation: 8337
You can bind the data from database directly to checkbox column if it is bit type in DB.
Upvotes: 2