开发者

How can I delete from a GridView when DataSource is a DataTable?

开发者 https://www.devze.com 2022-12-31 09:33 出处:网络
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 d

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消