getting the first 5 items in my xml datasource

Posted on 2011-10-14
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


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

            rptNews.DataSource = xDS
        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?
Question by:scm0sml
    LVL 2

    Accepted Solution

    you could try this:
    xDS.XPath = "rss/channel/item[position() <= 5]"


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

    Author Comment

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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now