我想在转发器中按年对新闻文章进行分组。格式为:
2010
文章列表
2011
文章列表
我的访问层返回新闻文章的平面列表,特别是 List。因此,我将它们分组并将它们绑定到中继器,如下所示:
events = DAL.GetEvents();
var groupedNewsList = from e in events
group e by e.StoryDate.Year
into g
select new {
Year = g.Key
, Events = g
};
rptEvents.DataSource = groupedNewsList;
rptEvents.DataBind();
问题是试图从 ItemDataBound 事件中获取列表。到目前为止,我有以下内容:
var data = e.Item.DataItem;
System.Type type = data.GetType();
// getting the year works fine
string year = (string)type.GetProperty("Year").GetValue(data, null).ToString();
// this returns something, but I can't access any properties. I need to get
//access to the contained List<News>
var newsList = type.GetProperty("Events").GetValue(data, null);
有任何想法吗?
提前致谢!