开发者

Repeater itemdatabound event value type and reference type

开发者 https://www.devze.com 2022-12-24 19:53 出处:网络
Im trying to bind a list with datetime objects to my repeater. if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)

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)开发者_JAVA技巧........


you are not correctly typing the DataItem

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号