473,750 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning only 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="Syst em.Xml" %>
<script language="VB" runat="server">
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
If Cache("RSS1") Is Nothing then
Dim dt as DataTable =
GetRSSFeed("htt p://rss.news.yahoo. com/rss/business")
Cache.Insert("R SS1", dt, Nothing, DateTime.Now.Ad dMinutes(180),
TimeSpan.Zero)
End If

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

Function GetRSSFeed(strU RL as String) as DataTable
Dim reader as XmlTextReader = New XmlTextReader(s trURL)

Dim ds as DataSet = New DataSet()
ds.ReadXml(read er)
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.Data Item, "link") %>"
target="_blank" ><%# DataBinder.Eval (Container.Data Item, "title")
%></a></b><br />
<%# DataBinder.Eval (Container.Data Item, "descriptio n")
%></font><br />
</itemtemplate>
</asp:DataList>
Thanks in advance,
Jeremy Reid
http://hgtit.com

Feb 22 '06 #1
4 1181
Jeremy

This is not a cut and paste answer as I have DataBound my datatable to
a Datagrid (called rss) for ease. I've also skipped out the Cache
stuff.

Should be simple for you to convert to your DataList & use the Cache

=============== =============== =============== ========
You could use DataView, filter it and then DataBind to the DataView
I notice that there is a Item_Id column in the DataTable returned from
GetRSSFeed()

Public Sub Page_Load(ByVal sender As System.Object, _
ByVal e As
System.EventArg s)

Dim dv As New DataView
Dim dt as DataTable = _

GetRSSFeed("htt p://rss.news.yahoo. com/rss/business")

dv = dt.DefaultView
dv.RowFilter = "Item_Id <3"

rss.DataSource = dv
rss.DataBind()

End Sub

Feb 22 '06 #2
Jeremy

This is not a cut and paste answer.

In working out a solution I have DataBound the datatable to a Datagrid
(called rss).

I've also skipped out the Cache stuff.

Should be simple for you to convert to your DataList & use the Cache

=============== =============== =============== ========
My solution is as follows, use a DataView, filter it and then DataBind
the DataView to the DataGrid (in your instance the DataList)

I notice that there is a Item_Id column in the DataTable returned from
GetRSSFeed() i used this value in the filter to get the first 3

Here's the code:

Public Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s)

Dim dv As New DataView
Dim dt as DataTable = _

GetRSSFeed("htt p://rss.news.yahoo. com/rss/business")

dv = dt.DefaultView
dv.RowFilter = "Item_Id <3"

rss.DataSource = dv
rss.DataBind()

End Sub

Feb 22 '06 #3
Question:

In this instance why does the <guid isPermaLink="fa lse"> node in each
of the item nodes of the RSS feed appear to become a index field called
"Item_Id" in the DataTable.

Is this a convention?

Feb 22 '06 #4
Thanks a lot man, that worked great! I ended taking what you gave and
still using the cache because theres too munch of a lag when it has to
go to yahoo and pull the feed every time a page is requested. This way
it caches it locally for 3 hours. Thanks again, this is what I have
now.
If Cache("RSS2") Is Nothing then
Dim dv As New DataView
Dim dt as DataTable =
GetRSSFeed("htt p://rss.news.yahoo. com/rss/business")
dv = dt.DefaultView
dv.RowFilter = "Item_Id < 4"
Cache.Insert("R SS2", dv, Nothing, DateTime.Now.Ad dMinutes(180),
TimeSpan.Zero)
End if
rss.DataSource = Cache("RSS2")
rss.DataBind()
End Sub
Function GetRSSFeed(strU RL as String) as DataTable
'Get the XML data
Dim reader as XmlTextReader = New XmlTextReader(s trURL)

'return a new DataSet
Dim ds as DataSet = New DataSet()
ds.ReadXml(read er)
Return ds.Tables(3)
End Function

It works great,

Thanks again.

Jeremy Reid
http://hgtit.com

Feb 22 '06 #5

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

Similar topics

6
2688
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 think that this is referred to as a histogram): i.e.:
4
4986
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 strings won't be known until just before the function returns. The problem is that in the calling function, I need to know both the address of the array, and the number of strings. My first thought was to pass a pointer to the array into the...
9
2438
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, strings for logging, and structures for data points. I want to use one function to read data from this block and one function to write data, for example: sram_read(OBJECT_IDENTIFIER) would return a pointer to the appriate object and
2
1758
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
1278
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 Google handles the pagination when a lot of pages are returned. That is: If you are at page 1 of 100 possible pages, you want to see the following:
1
2066
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 only have three weeks to finish it all! My GUI and Web services were finished, but I hadn't tested them. So I linked the GUI to the Web service and started testing them.
15
13512
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 http://msdn2.microsoft.com/en-us/library/ms996381.aspx Formerly, with classic Microsoft DNA architecture, the ADO Recordset was a primary transport medium, recommended for transmitting data between application tiers. In fact, there are whole books written on the subject.
5
1696
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 want to display some of the serial number values on a form which will have a diagram overlaid (to map out the "locations"). I have been trying to write an If statement in the controlsource properties of the text boxes to say "if location=position1...
19
1838
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 related answer here (by Eric Sosman) which involved creating an array of pointers and using that, so it looks something like:
5
2680
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 that structure, is this valid? As shown in the code below I am allocating the structure in the function and then returning the structure. I know if the structure contained only simple types (int, float) this will work without problems as you...
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.