[英]Fetch and Display RSS Feeds using ASP.Net
我需要閱讀並在我的網頁中顯示此提要。
使用c#net 2。
我嘗試了本教程:
http://www.aspsnippets.com/Articles/Fetch-and-Display-RSS-Feeds-using-ASP.Net.aspx
但是錯誤是:
A column named 'link' already belongs to this DataTable:
cannot set a nested table name to the same name.
為什么?
我的代碼如下。
我將非常感謝您在解決此問題方面可以給我的任何幫助。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="FeedPicasa_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rssRepeater" runat="server">
<ItemTemplate>
<table style="border: solid 1px black; width: 500px; font-family: Arial">
<tr>
<td style="font-weight: bold">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("link")%>' Text='<%#Eval("title")%>'></asp:HyperLink>
</td>
</tr>
<tr>
<td>
<hr />
</td>
</tr>
<tr>
<td style="background-color: #C2D69B">
<asp:Label ID="Label1" runat="server" Text='<%#Eval("description")%>'></asp:Label>
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
using System;
using System.Net;
using System.Xml;
using System.Data;
public partial class FeedPicasa_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetRSS();
}
private void GetRSS()
{
//Create a WebRequest
WebRequest rssReq =
WebRequest.Create("http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public");
//Create a Proxy
WebProxy px = new WebProxy("http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public", true);
//Assign the proxy to the WebRequest
rssReq.Proxy = px;
//Set the timeout in Seconds for the WebRequest
rssReq.Timeout = 5000;
try
{
//Get the WebResponse
WebResponse rep = rssReq.GetResponse();
//Read the Response in a XMLTextReader
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
//Create a new DataSet
DataSet ds = new DataSet();
//Read the Response into the DataSet
ds.ReadXml(xtr);
//Bind the Results to the Repeater
rssRepeater.DataSource = ds.Tables[2];
rssRepeater.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
}
如何使用純Javascript / jQuery解決方案,如下所示:
使用Javascript
$(function(){
url = 'http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public';
$.ajax({
type: "GET",
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
error: function(){
alert('Unable to load feed, Incorrect path or invalid feed');
},
success: function(xml){
values = xml.responseData.feed.entries;
$.each(values, function( index, value ) {
$('#myFeed').append(value.content);
$('#myFeed').append('<br/>');
});
}
});
});
HTML
<div id="myFeed"/>
工作提琴
描述
上面的代碼只是簡單地對feed進行json調用,在成功函數中,它循環結果並使用jQuery追加輸出feed的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.