【发布时间】:2011-05-21 13:05:05
【问题描述】:
我已将我的数据网格绑定到一个列表。我正在遵循存储库模式并使用 EF v4.1。我需要在 row_deleting 事件中删除实体。这是代码:
protected void grdBooks_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
{
int bookId = (int)e.Keys[0];
//grdBooks.Rows[e.RowIndex] //this item's dataItem is always null.
}
当我使用实体时,我需要实际的实体将其传递给我的 GenericRepository,这将删除该实体。我确实得到了 bookId,但我不想做一些愚蠢的事情,比如使用这个 bookId 从数据库中获取实体,然后将其传递给我的删除方法。为什么 DataItem 总是为空,我该怎么做才能取回我的实体?
【问题讨论】:
标签: c# asp.net entity-framework gridview aspxgridview