我正在尝试使用RSS-feed实现从System.ServiceModel.Syndication中获得的帖子的分页。然而,我不知道如何做到这一点,什么是最好的方法。
到目前为止,我使用一个Listview在代码背后显示由它获取的数据:
// Link to the RSS-feed.
string rssUri = "feed.xml";
var doc = System.Xml.Linq.XDocument.Load(rssUri);
// Using LINQ to loop out all posts containing the information i want.
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
select new
{
Title = el.Element("title").Value,
PubDate = el.Element("pubDate").Value,
Enclosure = el.Element("enclosure").Attribute("url").Value,
Description = el.Element("description").Value
};
// Binding the data to my listview, so I can present the data.
lvFeed.DataSource = rssFeed;
lvFeed.DataBind();那我该从这里去哪?我猜有一种方法是在我的DataPager中使用Listview?然而,我不确定如何使用该控件,是否应该将所有数据发送到某个列表或类似于IEnumerable<>的列表中
发布于 2014-04-11 14:13:30
经过一些尝试和错误,并阅读了DataPager,我想出了下面的解决方案,现在工作得很好!
首先,我为我的对象创建了一个类,使用它,我为在页面加载时启动的ListView设置了一个select方法,将数据绑定到它。这里的诀窍是使用ICollection接口,并将数据发送到列表中。这是这个select方法的工作代码,希望它能帮助其他人解决同样的问题!)
ICollection<Podcast> SampleData()
{
string rssUri = "http://test.test.com/rss";
var doc = System.Xml.Linq.XDocument.Load(rssUri);
ICollection<Podcast> p = (from el in doc.Elements("rss").Elements("channel").Elements("item")
select new Podcast
{
Title = el.Element("title").Value,
PubDate = el.Element("pubDate").Value,
Enclosure = el.Element("enclosure").Attribute("url").Value,
Description = el.Element("description").Value
}).ToList();
return p;
}https://stackoverflow.com/questions/23002866
复制相似问题