Using skmRss.RssFeed
I have been evaluating the use of Scott Mitchell's RSSFeed control for a new version of my website (it's not done yet) for my consulting company that focuses on the Cable Sector of the Telecommunications Industry and I wanted to display relevant information for both Web Services and the Cable Sector. The control is very nice (and free). During my investigation I wanted to perform a couple of actions that were not quickly apparent but still quite doable once I dug a bit deeper. Specifically, I wanted to be able to:
- Keep all items to a single row in the control (without wordwrap).
- Display ToolTips
To put all items in a single row, I noticed that it has a boolean called 'Wrap' for an ItemStyle; however, I could not get this to work so I took a nother approach. I modified the RSSDocument to shorten the title to display it correctly. Here is how I did it:
First the code to wire it up:
cableNewsFeed.DataSource = getList( [DataSource], __maxTitleLength, cableNewsFeed.MaxItems );
cableNewsFeed.DataBind();
Next the code to create the list:
protected RssDocument getList( string dataSource, int maxTitleLength, int maxFeedLength )
{
// create the engine and get the xml document
RssEngine engine = new RssEngine();
RssDocument sourceDocument = engine.GetDataSource( dataSource );
// all of the properties on the document are 'Get' only, so I created a copy.
RssDocument results = new RssDocument( sourceDocument.Title, sourceDocument.Link,
sourceDocument.Description, sourceDocument.Version, sourceDocument.FeedType,
sourceDocument.PubDate);
// get the max offset ( i pass it this in to the method based on the max items of control).
int countOffset = sourceDocument.Items.Count-1;
for( int i = 0; i < maxFeedLength && countOffset >= i; i++ )
{
// get the item to clone
RssItem item = sourceDocument.Items[i];
// shorten the title.
string title = getTitle( item.Title, maxTitleLength );
// add the 'New' item.
results.Items.Add( new RssItem( title, item.Link, item.Description,
item.Author, item.Category, item.Guid, item.PubDate, item.RssEnclosure ) );
}
// return the results.
return results;
}
Method to create the title:
protected string getTitle( string title, int maxLength )
{
int length = title.Length;
if( length > maxLength ) title = title.Substring(0,maxLength);
return title += "...";
}
If I were really industrious I would have created the method based on the GDI+ MeasureString method. However, I am not guarenteed that everyone will have the font on their machine. I still think it is worthy of doing this, but maybe later.
Next, I wanted the tool tip to display the description of the RSSFeed. To do this, I wired up the ItemDataBound event:
cableNewsFeed.ItemDataBound+=
new RssFeedItemEventHandler(cableNewsFeed_ItemDataBound);Now the method:
private void cableNewsFeed_ItemDataBound(object sender, RssFeedItemEventArgs e)
{
( ( System.Web.UI.WebControls.WebControl )e.Item).ToolTip = e.Item.DataItem.Description;
}
The results (btw, it will probably be under a different company name with different verbage):