How can I delete from a GridView when DataSource is a DataTable?
My DataSource is a DataTable populated from file system data in Page_Load. There is no database. How can I remove rows from the DataTable and re开发者_StackOverflow社区bind? I thought this had to be done in the GridView_RowCommand "Delete" section...
if(e.CommandName == "Delete")
...
When I try to access the DataRow's within
//get the datatable
DataTable dt = this.gridCPCP.DataSource as DataTable;
// Delete the record
foreach (DataRow dr in dt.Rows)
{
....
dt
is null. How do I reference the DataTable when deleting records?
e.CommandArgument should give you the index of the row which should be deleted. You could bind your datatable to the grid again without the deleted item.
精彩评论