2012-02-17 16 views
1

如何可靠的是這種方法嗎?我目前使用它,它在拉我進料精細,但如果我的博客是往下走或離線出於某種原因,整個頁面就報錯了。有沒有什麼辦法解決這一問題?或者只是提供一條錯誤消息,說「找不到Feed」。如何可靠的是XmlDataSource控件?

<asp:DataList ID="dataNews" runat="server" DataSourceID="xmlSource" > 
        <ItemTemplate> 
        <a href="<%# XPath("link") %>"><%# XPath("title") %></a><br /> 
        <%# XPath("description").ToString().Substring(0,100) %>... 
        </ItemTemplate> 
      </asp:DataList> 
      <asp:XmlDataSource ID="xmlSource" runat="server" DataFile="http://blogurl.com/feed" XPath="rss/channel/item[position()<4]" EnableCaching="false" /> 
+0

嘗試。 'http:// blogurl.local/feed'將不起作用。 – 2012-02-17 20:08:59

+0

這是一個示例網址。 – 2012-02-17 20:21:52

+0

那麼當你運行它時會發生什麼? – 2012-02-17 20:57:48

回答

1

您回答了您自己的問題。如果進料不能被成功加載,您的代碼應檢測到它並正常退出,即顯示一個錯誤消息,顯示的內容的交替位,等等

+0

哪些代碼? _____ – 2012-02-17 20:13:41

+0

@list你能做到這一點與我的代碼? – 2012-02-17 20:22:20

+1

沒有,但是看看這個問題的一個例子:http://stackoverflow.com/questions/2624251/handling-xmldatasource-when-remote-xml-source-not-available – Ryan 2012-02-17 20:33:48