Repeater itemdatabound 事件值类型和引用类型

发布于 2024-08-27 11:18:35 字数 393 浏览 5 评论 0原文

我试图将带有日期时间对象的列表绑定到我的中继器。

if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { DateTime 实际日期 = e.Item.DataItem as DateTime; 当

我想访问中继器上的 itemdatabound 事件时 然后我收到一条错误消息,指出 DateTime 是值类型而不是引用类型。 我的解决方案是将日期时间包装在自定义对象(引用类型)中,并将其传递给中继器数据源而不是日期时间。但我想知道是否还有其他解决方案,其中中继器采用值类型(DateTime 对象)........

Im trying to bind a list with datetime objects to my repeater.

if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
DateTime actualDate = e.Item.DataItem as DateTime;
}

When I want access the itemdatabound event on the repeater
Then I get an errormessage which says that DateTime is a valuetype and not a reference type.
My solution is that a wrap the datetime in a custom object (reference type) and pass that to the repeater datasource instead of the datetime. But Im wondering if there are other solutions where the repeater takes valuetypes (DateTime objects)........

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

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

发布评论

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

评论(1

时光病人 2024-09-03 11:18:35

您没有正确输入 DataItem

if (e.Item.ItemType == ListItemType.AlternatingItem || 
      e.Item.ItemType == ListItemType.Item) 
{ DateTime actualDate = (DateTime)e.Item.DataItem; }

you are not correctly typing the DataItem

if (e.Item.ItemType == ListItemType.AlternatingItem || 
      e.Item.ItemType == ListItemType.Item) 
{ DateTime actualDate = (DateTime)e.Item.DataItem; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文