如何在DataGrid中插入一列CheckBox,并且如何将选中的行删除?
我用其自带的属性生成器添加了一个自定义列,希望在其中加入Web控件CheckBox,然后可以选中一些需要删除的行进行删除操作。望指教.
解决方案是这样的:
如果直接在里面加入CheckBox控件,不太可能,绑定很烦,所以建议使用绑定列模式,在设计绑定列中,加入CheckBox控件,然后对绑定的数据进行后期数据绑定,就可以解决了。
are you using AutoPostBack on the CheckBox? if yes, you can get the item index in the event handler and delete the row and rebind your datagrid, otherwise, do
foreach (DataGridItem dgi in DataGrid1.Items)
{
CheckBox cb = (CheckBox)dgi.FindControl("YourCheckBoxID");
if (cb.Checked)
{
//do you deletion here
}
}
在一列中加入CHECKBOX控件可以向DataGrid中加入模板列,在加入CheckBox