0

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?

hnnnng
  • 481
  • 4
  • 21
  • Are you trying to add a number to a string? (ItemsToTake + 1) Because that won't work – hcb Apr 16 '14 at 14:26
  • I think that's exactly where my confusion is coming from. In my widget designer, I thought ItemsToTake is int since it's an input field where I can enter the number of feeds I want to be displayed. – hnnnng Apr 16 '14 at 14:46

0 Answers0