Parse XML to Repeater, show "Top 5"

Posted on 2007-07-23
Last Modified: 2007-12-19
I have a code that binds some info from a XML to a repeater. The code below works fine, but I only want to show "Top 5" elements from the XML. How can I show just some elements, not all?

<asp:Repeater runat="server" ID="repGames">
        <%# DataBinder.Eval(Container.DataItem, "Title") %><br />

protected void Page_Load(object sender, EventArgs e)
    getElements("", repGames, 4);

void getElements(string XMLpath,Repeater objRepeater, int iTable)
    DataSet oDs = new DataSet();
    objRepeater.DataSource = oDs.Tables[iTable];
Question by:webressurs
    LVL 12

    Accepted Solution

    you can use xpath facility to get top 5

     XmlDocument objDoc = new XmlDocument();

    XmlNodeList objList = new XmlNodeList();
    objList  = objDoc.SelectNodes("//NAMEOFYOURNODE/[position()<6]");

    Parse thru objList  


    LVL 29

    Assisted Solution

    another solution is probably to remove all but first five rows in the dataset table.
    Just llop through collection of rows and call RemoveAt(index) (DataRowCollection.RemoveAt Method )

    Then bind to repeater

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now