Only show X rows from DataGrid
Question
I want to post my 5 recent twitters on my website. I've build a datagrid with XMLTextReader in C# which reads the feed but the problem I face is that it shows ALL the feeds and I can't find a way to only show 5. Any idea's?
XmlTextReader reader = new XmlTextReader("http://some.rss/feed.rss");
DataSet ds = new DataSet();
ds.ReadXml(reader);
dg.DataSource = ds.Tables[2];
dg.AutoGenerateColumns = false;
dg.AllowPaging = false;
dg.DataBind();
Solution
to answer directly your question:
<asp:GridView ID="gv" runat="server"
PageSize="5" AllowPaging="true">
<PagerSettings Visible="false" />
</asp:GridView>
But I'm just wondering, why not trying to use a C# wrapper for Twitter API?
like:
http://devblog.yedda.com/index.php/2007/05/16/twitter-c-library/
or follow the fantastic post of Petar in
http://blogs.vertigo.com/personal/petar/Blog/archive/2008/06/23/twitter-wcf-client.aspx
P.S. add twitter to your tags!
OTHER TIPS
How about the simple solution of manually deleting all the rows from the DataTable except the first 5?
Better still, the Twitter API allows you to specify a "since ID" value. That way you can request only updates since the latest one you have.