ASP.Net:在编辑和删除的GridView从获取DataKey [英] ASP.Net: Getting DataKey from GridView on Edit and Delete
问题描述
我使用的是数据绑定到一个列表
的对象从实用方法返回一个 GridView控件
控制。在 GridView控件
控件设置为DataKey的一列。当行被选中 ,它触发选定的事件处理程序,我可以使用
myGridView.SelectedDataKey.Value
来获得对所选择的行的DataKey列的值。
但是,事件处理程序,当行编辑
或删除
似乎没有一种机制来获得所讨论的行的DataKey值。这些事件处理事件arg参数包含行的该指数 GridView控件
,但我的DataKey值之后专门来的。
重新获得对象的名单是不是一种选择,因为对象的名单可能已经改变。
谁能告诉我怎样才能做到这一点?
TIA
保护无效gridQuestion_RowDeleting(对象发件人,GridViewDeleteEventArgs E)
{
INT ID =(int)的grdQuestions.DataKeys [e.RowIndex] .value的;
}
I am using a GridView
control which is databound to a List
of objects returned from a utility method. The GridView
control has one of the columns set as its DataKey. When a row is Selected
, it fires the Selected event handler and I can use myGridView.SelectedDataKey.Value
to get the value of the DataKey column for the selected row.
However, the event handler for when a row is Edited
or Deleted
does not seem to have a mechanism to get the DataKey value for the row in question. The event arg parameter for these event handlers contains the index of the row in the GridView
but I'm specifically after the DataKey value.
Re-obtaining the List of objects via the utility method along with the index obtained from the event arg parameter is not an option because the List of objects may have changed.
Can anyone tell me how I can do this?
TIA
protected void gridQuestion_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = (int)grdQuestions.DataKeys[e.RowIndex].Value;
}
这篇关于ASP.Net:在编辑和删除的GridView从获取DataKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!