如何将Datakeys访问gridView_RowEditing [英] How to acces Datakeys into a gridView_RowEditing

查看:66
本文介绍了如何将Datakeys访问gridView_RowEditing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网格中访问一个datakey列,如果是行编辑,我的代码是



 私有  Sub  grdOdGovori_RowEditing(sender  As  对象,e 作为 GridViewEditEventArgs)句柄 grdOdGovori.RowEditing 



Apoen = CDec (grdOdGovori.Rows(e.NewEditIndex).Cells( 1 )。文本)

VidTestiraniPari = grdOdGovori.SelectedDataKey( Sifratestirani)。ToString
BindGridRezultati()

结束 Sub





错误是:对象引用未设置为对象的实例。如何在您的gird aspx页面中访问Datakey ??

解决方案

,将DataKeyNames属性设置为您的键列名,例如,如果它是ID则

 asp:GridView DataKeyNames =   ID 



然后在你的事件方法中你可以得到如下的id值

 grdOdGovori.DataKeys(e。 RowIndex).Value 



ref:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames( v = vs.110).aspx [ ^ ]

如果你有多个密钥如下

 asp:GridView DataKeyNames =ID,ID2



你可以得到如下所示的每个键

grdOdGovori.DataKeys(e.RowIndex).Values(ID1)。ToString() grdOdGovori.DataKeys(e.RowIndex).Values( ID2)。的ToString()


I want to acces a datakey column into my grid, in the event of row editting, MY code is

Private Sub grdOdGovori_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles grdOdGovori.RowEditing
     

     
      Apoen = CDec(grdOdGovori.Rows(e.NewEditIndex).Cells(1).Text)
     
      VidTestiraniPari = grdOdGovori.SelectedDataKey("Sifratestirani").ToString
      BindGridRezultati()

  End Sub



And the error is: Object reference not set to an instance of an object. How can I acces the Datakey??

解决方案

in your gird aspx page, set the DataKeyNames property as your key column name, for example if it is ID then

asp:GridView DataKeyNames ="ID" 


then in your event method you can get the id value as below

grdOdGovori.DataKeys(e.RowIndex).Value


ref:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames(v=vs.110).aspx[^]
if you have multiple keys as below

asp:GridView DataKeyNames ="ID,ID2" 


then you can get each key as below
grdOdGovori.DataKeys(e.RowIndex).Values("ID1").ToString() and grdOdGovori.DataKeys(e.RowIndex).Values("ID2").ToString()


这篇关于如何将Datakeys访问gridView_RowEditing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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