473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Returning top X number of items...

Here is my working code to pull Yahoo business news RSS feed. Can
anyone show me how to only return the top 3 or 4 news articles?

<%@ Import Namespace="System.Xml" %>
<script language="VB" runat="server">
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If Cache("RSS1") Is Nothing then
Dim dt as DataTable =
GetRSSFeed("http://rss.news.yahoo.com/rss/business")
Cache.Insert("RSS1", dt, Nothing, DateTime.Now.AddMinutes(180),
TimeSpan.Zero)
End If

rss.DataSource = Cache("RSS1")
rss.DataBind()
End Sub

Function GetRSSFeed(strURL as String) as DataTable
Dim reader as XmlTextReader = New XmlTextReader(strURL)

Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)
Return ds.Tables(3)
End Function
</script>
<asp:DataList runat="server" id="rss">
<itemtemplate>
<font size="2" face="Geneva, Arial, Helvetica, san-serif"><b><a
href="<%# DataBinder.Eval(Container.DataItem, "link") %>"
target="_blank"><%# DataBinder.Eval(Container.DataItem, "title")
%></a></b><br />
<%# DataBinder.Eval(Container.DataItem, "description")
%></font><br />
</itemtemplate>
</asp:DataList>
Thanks in advance,
Jeremy Reid
http://hgtit.com

Feb 22 '06 #1
2 973
Jeremy,
Just iterate over the rows in your DataTable and call the DataRow.Delete()
method
on as many as you want.
Then call AcceptChanges on the table.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"blackstaronline.net" wrote:
Here is my working code to pull Yahoo business news RSS feed. Can
anyone show me how to only return the top 3 or 4 news articles?

<%@ Import Namespace="System.Xml" %>
<script language="VB" runat="server">
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If Cache("RSS1") Is Nothing then
Dim dt as DataTable =
GetRSSFeed("http://rss.news.yahoo.com/rss/business")
Cache.Insert("RSS1", dt, Nothing, DateTime.Now.AddMinutes(180),
TimeSpan.Zero)
End If

rss.DataSource = Cache("RSS1")
rss.DataBind()
End Sub

Function GetRSSFeed(strURL as String) as DataTable
Dim reader as XmlTextReader = New XmlTextReader(strURL)

Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)
Return ds.Tables(3)
End Function
</script>
<asp:DataList runat="server" id="rss">
<itemtemplate>
<font size="2" face="Geneva, Arial, Helvetica, san-serif"><b><a
href="<%# DataBinder.Eval(Container.DataItem, "link") %>"
target="_blank"><%# DataBinder.Eval(Container.DataItem, "title")
%></a></b><br />
<%# DataBinder.Eval(Container.DataItem, "description")
%></font><br />
</itemtemplate>
</asp:DataList>
Thanks in advance,
Jeremy Reid
http://hgtit.com

Feb 22 '06 #2
Thanks for your help Peter. What I ended up doing was calling the
Row.Filter and it seems to works great. Can you think of a reason why
DataRow.Delete() is a better suited fix? If so I'll use it but this
seems to work great.

If Cache("RSS2") Is Nothing then
Dim dv As New DataView
Dim dt as DataTable =
GetRSSFeed("http://rss.news.yahoo.com/rss/business")
dv = dt.DefaultView
dv.RowFilter = "Item_Id < 4"
Cache.Insert("RSS2", dv, Nothing, DateTime.Now.AddMinutes(180),
TimeSpan.Zero)
End if
rss.DataSource = Cache("RSS2")
rss.DataBind()
End Sub
Function GetRSSFeed(strURL as String) as DataTable
'Get the XML data
Dim reader as XmlTextReader = New XmlTextReader(strURL)

'return a new DataSet
Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)
Return ds.Tables(3)
End Function
Thanks again for your help Peter,
Jeremy Reid
http://hgtit.com

Feb 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ric Deez | last post by:
Hi there, I have a list: L1 = How can I easily turn this into a list of tuples where the first element is the list element and the second is the number of times it occurs in the list (I...
4
by: Anthony | last post by:
Hello, I am writing a function that populates an array of pointers to strings. Both the number of strings in the array, and the lengths of the strings, are dynamic; in particular, the number of...
9
by: CptDondo | last post by:
I am working on an embedded platform which has a block of battery-backed RAM. I need to store various types of data in this block of memory - for example, bitmapped data for control registers,...
2
by: Maziar Aflatoun | last post by:
Hi, Does anyone know how I can return the index number of a ListBox? Ex. How do I use lbxMyListBox.Items.IndexOf to search for the item that has a Text="Name" Thanks Maz.
1
by: Henrik | last post by:
Hello all. I'm after some sort of pagination function. One that takes some in data that I provide, and returns an array of controls, pointing to page 2, page 3 etc. Trying to mimic the way that...
1
by: Matthias De Ridder | last post by:
Hello, I really hope that someone will be able to help me, because I'm desperate now! I'm a student, graduating this year, and I'm working on a thesis where C# Web Services are involved. I...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
5
by: littlevikinggirl | last post by:
Hi, I posted a badly worded question last week so got no replies and am still struggling to figure out the problem myself. I have a table containing two fields, Location and Serial Number. I...
19
by: Adam | last post by:
Hi, I'd like to return an (arbitrary length) string array from a function so that after calling the array I've got a list of strings I can access. After much perusing of the internet I found a...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.