2012-03-26 91 views
2

我試圖限制通過傳遞給一個asp.net轉發器的XML源的記錄數。如何限制在asp.net中的XML源中顯示的記錄數量?

有數以百計的「記錄」,我想限制直放站4

任何幫助表示讚賞。謝謝!

我後面的代碼:

protected void XMLsource() 
{ 
    string URLString = "http://ExternalSite.com/xmlfeed.asp"; 

    XmlDataSource x = new XmlDataSource(); 
    x.DataFile = URLString; 
    x.XPath = String.Format(@"root/mainNode"); 

    xPathRepeater.DataSource = x; 
    xPathRepeater.DataBind(); 
} 

我的前端代碼:

<asp:Repeater ID="xPathRepeater" runat="server"> 
    <ItemTemplate> 
     <li> 
      <h1><%#XPath ("title") %></h1> 
     </li> 
    </ItemTemplate> 
    </asp:Repeater> 

回答

3
xPathRepeater.DataSource = x.Data.Take(4); 
xPathRepeater.DataBind(); 
+0

出於某種原因,這其實沒有工作。可能是我的結局。頁面呈現,但空了。謝謝! – 2012-03-26 16:46:47

+0

這將'Repeater'綁定到一個字符串列表...應該工作...確保'Repeater'中的代碼正確綁定... – xandercoded 2012-03-26 16:53:20

+0

'

<%#Container.DataItem%>

' – xandercoded 2012-03-26 16:54:09

1

或者:

x.XPath = String.Format(@"root/mainNode [position() < 5]"); 
相關問題