我如何删除一个GridView连续RowDeleting活动期间? [英] How do I delete a row from a GridView during the RowDeleting event?
问题描述
我有一个GridView和其DataSource是GridView控件 datatable.OnRowDeleting
事件。我似乎无法删除该行,当我点击删除按钮调用该事件以删除该行。
I have a GridView and its DataSource is datatable.OnRowDeleting
event of Gridview. I can't seem to delete that row when I click the 'delete' button that invokes the event to remove the row.
我的code是这样的GridView控件的 RowDeleting
事件:
My code is like this in RowDeleting
event of GridView:
DataTable.Rows.Remove(GridView.DataKeys(e.rowindex).value)
我得到的错误:
I get the error:
不能键入从System.Int32中投地的System.Data.DataRow
有没有人有什么建议?
推荐答案
您可以找到通过查看 RowDeleting
事件中删除的行
You can find the row to delete inside the RowDeleting
event by looking at the
e.RowIndex
您可以用 e.RowIndex
找到你的的DataTable正确的行
,删除该行,然后刷新你的GridView
通过调用.databind()就可以再次到数据表
。
You can then use the e.RowIndex
to find the proper row in your DataTable
, delete that row, and then refresh you gridview
by calling .databind() on it once again to that DataTable
.
示例:
DataTable1.Rows(e.RowIndex).Delete()
GridView1.DataSource = DataTable1
GridView1.DataBind()
这篇关于我如何删除一个GridView连续RowDeleting活动期间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!