2013-02-11 4 views

ответ

0

Использование DataGrid.ItemCommand Event

Пример кода:

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

    } 
+0

У меня нет taht: Событие ItemCommand возникает при нажатии любой кнопки в элементе управления DataGrid. Это событие обычно используется для управления элементами кнопок с пользовательским значением CommandName, таким как «Добавить», в элементе управления DataGrid. – user2061558

0

Если DataGrid ограничен источником, то есть datatable удаляет datarow из источника (datatable), а затем повторно привязывает сетку к источнику данных.

... 
    dtable.rows(i).Delete 
    myDataGrid.DataSource = dtable 
    myDataGrid.DataBind 
... 
Смежные вопросы