如何获取repeater_itemdatabound事件中的一列值?

发布于 2024-12-02 09:49:03 字数 159 浏览 3 评论 0原文

我在 ASP.NET 应用程序中使用中继器来显示数据库中的记录。绑定到转发器的数据源是数据表的记录。

如何获取中继器的 itemdatabound 事件中某一项的一列值?

我想获取名为“id”的列的值。如何在后端的repeater_itemdatabound事件中获取它?

I use repeater in my asp.net application to display records from database. The datasource that binded to repeater are records of a datatable.

How can I get one column value for an item in repeater's itemdatabound event?

I want to get a value of column called 'id'. How to get it in the repeater_itemdatabound event in backend?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昵称有卵用 2024-12-09 09:49:03

在 Repeaters ItemDataBound 事件中,您可以通过 e.Item.DataItem 属性提取绑定到项目的对象,然后执行以下操作:

var item = e.Item.DataItem as MyObject;
if (item.ID > 0)
   //Do something

In the Repeaters ItemDataBound event, you can extract the object bound to the item via the e.Item.DataItem property, and do:

var item = e.Item.DataItem as MyObject;
if (item.ID > 0)
   //Do something
夏天碎花小短裙 2024-12-09 09:49:03

在项目数据绑定事件中,您可以访问事件参数(变量 e)
e.Item.DataItem 是当前正在绑定的记录。请务必将其转换为 DataRow 或绑定集合中项目的任何类型。

您可以访问 ID 列

    Dim dr As System.Data.DataRow = DirectCast(e.Item.DataItem, System.Data.DataRow)
    Dim id As Int64 = dr("ID")

In the item databound event you have access to the event arguments (variable e)
e.Item.DataItem is the record that is currently being bound. Be sure to cast it as a DataRow or whatever the type is of the item in the collection being bound.

You could access the ID column

    Dim dr As System.Data.DataRow = DirectCast(e.Item.DataItem, System.Data.DataRow)
    Dim id As Int64 = dr("ID")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文