怎么获取DataGridView里的checkbox里的值
我在DataGridView里放入了一个checkBox列,然后用foreach()遍历里面选中的值但出现异常说为将对象引用设置到实例,代码如下:foreach (DataGridViewRow dgvr in dgvAdmin.Rows)
{
if (dgvr.Cells["check"].Value.ToString() == "1")
{
}
}
那里错了,高手帮帮忙 --------------------编程问答-------------------- 就是说没有找到checkbox ,用 CheckBox box=(CheckBox)dgvr.Cells[列索引].FindControl("check")as CheckBox, 得到CheckBox 对象后,就好操作了 --------------------编程问答-------------------- foreach (DataGridViewRow dgvr in dgvAdmin.Rows)
{
if (dgvr.Cells["check"].FormattedValue.ToString() == "1")
{
}
}
--------------------编程问答-------------------- foreach (DataGridViewRow dgvr in dgvAdmin.Rows)
{
bool check = Convert.ToBoolean(dgvr.Cells["check"].FormattedValue);
if ( check )
{
}
else
{
}
}
--------------------编程问答-------------------- FindControl方法,注意类型的转换 --------------------编程问答-------------------- 我怎么没找到FindControl方法 --------------------编程问答--------------------
正解
补充:.NET技术 , C#