5.24 How do I determine whether a checkbox in my datagrid is checked or not? If the column is a boolean column, you can just cast the object returned by the indexer to a bool and use it.
if((bool)dataGridTopics[row, column])
MessageBox.Show("I am true");
else
MessageBox.Show("I am false");
if((bool)dataGridTopics[row, column])
MessageBox.Show("I am true");
else
MessageBox.Show("I am false");
for( int i = 0; i < MyDataGrid.Items.Count; i++ ){
CheckBox chk = ( CheckBox )MyDataGrid.Items[i].FindControl("chk1");
if( chk.Checked )
{
......
}
else{
....
}
}
{
//查找CheckBox控件
CheckBox ch= (CheckBox)DataGrid1.Items[i].FindControl("CheckBox1");
}
, 我用这种方法找在其他控件(比如Panel)里的CheckBox并访问其值是没有问题的, 但是就是DataGrid里面的CheckBox, 每当点击按钮, DataGrid自动更新, 并把选中变为未选中!!!!!!也就是按钮里面的代码, 每次都是false哦, 这是怎么回事啊?