I created an Rss feed reader user control for my Sitefinity web app by using XMLDataSource.
In the code below, ItemsToTake is a public property for my user control widget designer. If the user enters 10, then 9 feeds will be displayed on the website.
I want to tweak this code the way the number entered by the user matches the number of feeds displaying on the website.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SitefinityWebApp.CustomWidgets.RssFeedReader
{
[Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesigner(typeof(SitefinityWebApp.CustomWidgets.RssFeedReader.WidgetDesigner_Chapters))]
public partial class MetroChapter : System.Web.UI.UserControl
{
public string RssFeedURL { get; set; }
public string ItemsToTake { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(RssFeedURL))
{
XmlDataSource1.DataFile = "http://www.npr.org/rss/rss.php?id=1001";
}
else
{
XmlDataSource1.DataFile = RssFeedURL;
}
if (string.IsNullOrEmpty(ItemsToTake))
{
XmlDataSource1.XPath = "rss/channel/item[position() < 6]";
}
else
{
XmlDataSource1.XPath = "rss/channel/item[position() <" + ItemsToTake + "]";
}
XmlDataSource1.Data = "XmlDataSource1";
XmlDataSource1.DataBind();
}
}
}
The easiest solution I could think of was raising the number by 1, so I did this:
XmlDataSource1.XPath = "rss/channel/item[position() <" + (ItemsToTake + 1) + "]";
but that didn't work. What's the best way to add a number to this property with an operator?