By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,016 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,016 IT Pros & Developers. It's quick & easy.

How do you delete a row from a DataGrid using a DataTable?

P: n/a
I'm trying to delete a row from a DataGrid using a ButtonColumn with
CommandName="Delete" by deleting the row in the underlying DataTable
datasource, but it doesn't seem to be working at the minute. I'm using
session data to fill the DataTable which subsequently fills the DataGrid.
The code is as follows (with "dgBasket" as the DataGrid):

private void dgBasket_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)


int rowToDelete = e.Item.ItemIndex;
DataTable myTable = (DataTable) Session["Basket"];

DataRowCollection myRows = myTable.Rows;

DataRow thisRow = myTable.Rows.Find(rowToDelete);


Session["Basket"] = myTable;

dgBasket.DataSource = myTable;

dgBasket.EditItemIndex = -1;

dgBasket.DataKeyField = "Product";



The page builds successully with no errors but nothing happens when I press
one of the delete buttons- the page reloads but the info doesn't delete.
Does anyone know where I'm going wrong?

Mark Jones
Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.