This article is straight foreword. The first snip is the HTML and the second snip is the code behind.
HTML:
<table style="width: 600px">
<tr>
<td>
<asp:DataList ID="DLRss" runat="server" DataKeyField="item_Id" Width="600px" >
<ItemTemplate>
<table style="width: 600px" >
<tr>
<td>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>' Font-Bold="True" Font-Size="Small"></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label ID="lblPubDate" runat="server" Text="Published:"></asp:Label> <asp:Label ID="Label1" runat="server" Text='<%# Eval("pubDate") %>'></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label Width="600px" ID="lblItem" runat="server" Text='<%# Eval("description") %>'></asp:Label></td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lbtnLink" runat="server" onClientClick='<%# Eval("link") %>' OnClick="lbtnLink_Click" Font-Underline="True">Read Full Article</asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList></td>
</tr>
</table>
Code Behind:
#Region "Event Handlers"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim sb As StringBuilder
Dim i As Integer
Try
If Not Page.IsPostBack Then
ds.ReadXml("SomeRSS-URL", XmlReadMode.Auto)
If ds.Tables("item").Columns.Contains("item_Id") = False Then
ds.Tables("item").Columns.Add("item_Id")
End If
For i = 0 To ds.Tables("item").Rows.Count - 1
ds.Tables("item").Rows(i).Item("item_Id") = i
sb = New StringBuilder
sb.Append("javascript:window.open('")
sb.Append(ds.Tables("item").Rows(i).Item("link").ToString)
sb.Append("');return false;")
ds.Tables("item").Rows(i).Item("link") = sb.ToString
Next
DLRss.DataSource = ds.Tables("item")
DLRss.DataBind()
End If
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
Finally
ds.Dispose()
End Try
End Sub
#End Region
How the reader works:
Paste the code on a page and do the same on the code behind. On the "SomeRSS-URL" pass in the url to an rss link. For example, if you wanted to see Google Tech News, you would enter this link: http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&topic=t&output=rss. You can pass the url in any way you like. For example, you could use the session or post in the query string. I would not suggest using the querystring for this though; there is a max length on a querystring. If your url exceedes the max query string it gets truncated and you also have potential security issues. When the form loads the url is consumed by a Dataset and and the table named "item" has the data you are looking for. This table has a column called "link" which is the url for the article, we are going to modify this column with some javascript and bind it to a link button on the datalist. Take note that the end of the javascript snip has the command "return false;" this prevents the browser from following the link; it also prevents the browser from making a post back.
In my next update I will provide a very easy way to create a DotNetNuke module with this concept and a very easy way to pass in the url.
Best Regards,
Sean Gahan