ASP/VB.netで
DATAGRIDで、Grid_ItemDataBoundの行を削除したい
データグリッドから行を削除する方法をすでに試し ましたか? しかし、私が必要としているのは本当にそうではありません
ASP/VB.netで
DATAGRIDで、Grid_ItemDataBoundの行を削除したい
データグリッドから行を削除する方法をすでに試し ましたか? しかし、私が必要としているのは本当にそうではありません
DataGrid.ItemCommand イベントを使用する
サンプルコード:
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();
}
DataGrid がソースにバインドされている場合、つまり datatable は、ソース (datatable) からデータ行を削除してから、グリッドをデータソースに再バインドします。
...
dtable.rows(i).Delete
myDataGrid.DataSource = dtable
myDataGrid.DataBind
...