在 ASP/VB.net 中
在我的 DATAGRID 中,我想删除 Grid_ItemDataBound 中的一行
我已经尝试过 如何从数据网格中删除行? 但这不是我真正需要的吗
如果DataGrid 绑定到源,即数据表从源(数据表)中删除数据行,然后将网格重新绑定到数据源。
...
dtable.rows(i).Delete
myDataGrid.DataSource = dtable
myDataGrid.DataBind
...
示例代码:
void ItemsGrid_Command(Object sender, DataGridCommandEventArgs e)
{
switch(((LinkButton)e.CommandSource).CommandName)
{
case "Delete":
DeleteItem(e);
break;
// Add other cases here, if there are multiple ButtonColumns in
// the DataGrid control.
default:
// Do nothing.
break;
}
}
void DeleteItem(DataGridCommandEventArgs e)
{
// e.Item is the table row where the command is raised. For bound
// columns, the value is stored in the Text property of a TableCell.
TableCell itemCell = e.Item.Cells[2];
string item = itemCell.Text;
// Remove the selected item from the data source.
CartView.RowFilter = "Item='" + item + "'";
if (CartView.Count > 0)
{
CartView.Delete(0);
}
CartView.RowFilter = "";
// Rebind the data source to refresh the DataGrid control.
BindGrid();
}