0

ASP/VB.netで

DATAGRIDで、Grid_ItemDataBoundの行を削除したい

データグリッドから行を削除する方法をすでに試し ましたか? しかし、私が必要としているのは本当にそうではありません

4

2 に答える 2

0

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();

  }
于 2013-02-11T14:36:15.310 に答える
0

DataGrid がソースにバインドされている場合、つまり datatable は、ソース (datatable) からデータ行を削除してから、グリッドをデータソースに再バインドします。

...
    dtable.rows(i).Delete
    myDataGrid.DataSource = dtable
    myDataGrid.DataBind
...
于 2013-02-12T11:19:08.760 に答える