拥有autoid时如何在gridview中访问数据键 [英] How to access the datakey in gridview when we have the autoid
本文介绍了拥有autoid时如何在gridview中访问数据键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在网格视图中,我有两个绑定字段和一个复选框.绑定字段中的值来自表.现在,我要访问autoid的值,并在其中存储所选复选框的会话.
I have two bound fields and one check box in grid view . And the values in bound field comes from the table . Now i want to access the value of the autoid and store in it a session of the selected checkbox.
推荐答案
我不清楚你的问题.您是否要在gridview中保留行的主键?如果是这样,您可以为此使用隐藏字段.
Hi,
I am not clear on your question. Do you want to keep primary key of the rows in the gridview? If so you can use a hidden field for this.
使用此
Use this
GridView1.DataKeys[index].Value.ToString()
这里index
是gridview的行索引
检查此链接
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx [ DataKeyNames [
here index
is row index of gridview
check this link
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx[^]
You can have multiple datakeys to access them see this link
DataKeyNames[^]
尝试以下操作:
Try this one:
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
HiddenObjectID.Value = Convert.ToString(GvUserDetails.DataKeys[row.RowIndex].Value);
这篇关于拥有autoid时如何在gridview中访问数据键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文