从ASP.NET的ListView中的一行中获取数据库ID [英] Get database ID from a row in ListView in ASP.NET
问题描述
我在ASP.NET中有一个 ListView
,其中一列包含 CheckBox
.为了在用户更改时单击以更新数据库,我使用 OnCheckedChanged
.但是我怎么知道每个复选框与数据库中的哪条记录相关?
I have a ListView
in ASP.NET where one column contains CheckBox
. In order to get the database updated when the users change click them, I use OnCheckedChanged
. But how do I know which record in the database each checkbox is related to?
推荐答案
您应将DataKeys属性设置为代表单个记录ID的字符串.
You should set the DataKeys property to the string which represents the individual record ID.
一旦您处于商品数据绑定"事件中,就可以使用以下方式引用ID值:
Once you are in the Item Data Bound event you can then reference the ID value using;
DataKey currentDataKey = myListView.DataKeys[e.Item.DataItemIndex];
然后,您只需使用currentDataKey值查找数据库记录即可.
You then simply lookup your database record using the currentDataKey value.
这篇关于从ASP.NET的ListView中的一行中获取数据库ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!