RSS使用System.ServiceModel.Syndication的寻呼 [英] Paging of RSS using System.ServiceModel.Syndication

查看:107
本文介绍了RSS使用System.ServiceModel.Syndication的寻呼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现我的职位从 RSS源使用获得的分页 System.ServiceModel.Syndication 。不过,我找不出如何做到这一点,如何做到这一点的最好办法是。

I'm trying to achieve pagination of the posts i get from a RSS-feed using the System.ServiceModel.Syndication. However I cant figure out how to do this and what the best way to do it is.

截至目前我使用的是列表视图来present即获取了这在我的code-背后的数据:

As of now i use a Listview to present the data that is fetched by this in my code-behind:

// 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的在我的列表视图工作?但是我不确定如何与控制工作,我应该把我所有的数据转换成一些列表或类似的IEnumerable&LT东西;>

So where do I go from here? I'm guessing one way is to work with a DataPager in my Listview? However I'm uncertain how to work with that control, should I send all of my data into some list or something like IEnumerable<>?

推荐答案

一些试验和错误,并在阅读完毕后的 DataPager的我想出了以下解决方案,现在的工作非常好!

After some trial and error and reading up on the DataPager i came up with the following solution that is now working very well!

首先,我创建了一个类为我的对象,与我建立了我的的ListView 开始在页面加载数据绑定到它的选择 - 法工作。这里的诀窍是使用的ICollection 接口,将数据发送到一个列表。这是现在的工作code表示选择法,希望它可以帮助别人了面临同样的问题! :)

First off i created a class for my object, working with that i set up a select-method for my ListView initiating at page-load binding the data to it. And the trick here was to use the ICollection interface, and send the data to a list. This is the now working code for that select-method, hope it can help someone else out facing the same problem! :)

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;
    }

这篇关于RSS使用System.ServiceModel.Syndication的寻呼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆