[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

getting the first 5 items in my xml datasource

Posted on 2011-10-14
2
Medium Priority
?
282 Views
Last Modified: 2012-08-14
I have the following on my .aspx:
<asp:XmlDataSource ID="xDS" runat="server"></asp:XmlDataSource>

I then have in my code behind:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim xmlDoc As New XmlDocument

            xmlDoc.Load("http://www.shponline.co.uk/incourt-content/-/journal/rss/10704/55813?doAsGroupId=10704&refererPlid=10708")

            xDS.Data = xmlDoc.OuterXml
            xDS.DataBind()
            xDS.XPath = "rss/channel/item"

            rptNews.DataSource = xDS
            rptNews.DataBind()
        End If
    End Sub

This works fine.

The only problem is that I only want to display the first 5 items.

Is there a simple way of doing this using the xmldatasource?
0
Comment
Question by:scm0sml
2 Comments
 
LVL 2

Accepted Solution

by:
cslimrun earned 2000 total points
ID: 36970825
you could try this:
xDS.XPath = "rss/channel/item[position() <= 5]"

or

load the xml into a dataset and use a dataview to filter down to just the top 5 rows.
0
 

Author Comment

by:scm0sml
ID: 36973065
this worked nicely:
xDS.XPath = "rss/channel/item[position() <= 4]"
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question