ASP.Net:在编辑和删除的GridView从获取DataKey [英] ASP.Net: Getting DataKey from GridView on Edit and Delete

查看:304
本文介绍了ASP.Net:在编辑和删除的GridView从获取DataKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是数据绑定到一个列表的对象从实用方法返回一个 GridView控件控制。在 GridView控件控件设置为DataKey的一列。当行被选中 ,它触发选定的事件处理程序,我可以使用 myGridView.SelectedDataKey.Value 来获得对所选择的行的DataKey列的值。

但是,事件处理程序,当行编辑删除似乎没有一种机制来获得所讨论的行的DataKey值。这些事件处理事件arg参数包含行的该指数 GridView控件,但我的DataKey值之后专门来的。

通过从事件arg参数获得的指数沿实用方法

重新获得对象的名单是不是一种选择,因为对象的名单可能已经改变。

谁能告诉我怎样才能做到这一点?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆