在没有primarykey列的情况下获取gridview的主键 [英] Getting the primary key of a gridview without a primarykey column

查看:87
本文介绍了在没有primarykey列的情况下获取gridview的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不显示primarykey列的情况下获取所选gridview行的主键?这该怎么做?谢谢。

Is it possible to get the primary key of selected gridview row without the display of the primarykey column? How to do this? Thanks.

推荐答案

隐藏主键列,如Visible =false
Hide primary Key Column like Visible="false"


GridView1.Columns [0] .Visible = false ;

试试这段代码/ ....其中colom [colomindex] ..这里我使用0 ...
GridView1.Columns[0].Visible = false;
try this code/.... where colom[colomindex].. here I use 0...




隐藏列不是解决问题的好方法,您可以使用templatefield和DataKey轻松解决问题。将主键列名称分配给DataKey。查看下面的示例,



http:/ /msdn.microsoft.com/en-us/library/bb288031.aspx [ ^ ]



稍后您可以使用,
$ b获取所选行的主键$ b
Hi,
Hiding column is not good solution to your problem, You can easily solve your issue with templatefield and DataKey. assign your primary key column name into DataKey. Checkout the example below,

http://msdn.microsoft.com/en-us/library/bb288031.aspx[^]

Later you can get the primary key of the selected row by using,
DataKey currentKey = myGridView.SelectedDataKey;



希望这会有所帮助。


Hope this will help.


这篇关于在没有primarykey列的情况下获取gridview的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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