NumericalRangeCriteria (ASP.NET)

The following is an example of using the NumericalRangeCriteria to retrieve content which has a specific custom metadata value within the specified range of values:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Tridion.ContentDelivery.DynamicContent.Query;
using Tridion.ContentDelivery.DynamicContent;

namespace TestTaxonomies
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            // Create query            
            string strComponentTemplateURI = "tcm:4-17-32";
            int iPublicationID = 4;

            Query myQuery = new Query();
            Criteria myCriteria = null;
            NumericalRangeCriteria numericalRangeCriteria = new NumericalRangeCriteria("Number", 0, 1000);
            // Return all items with float value custom metadata

            ItemTypeCriteria itemTypeCriteria = new ItemTypeCriteria(16);
            // Only return Components

            AndCriteria andCriteria = new AndCriteria(numericalRangeCriteria, itemTypeCriteria);

            myCriteria = andCriteria;

            myQuery.Criteria = myCriteria;

            SortParameter sortParameter = new SortParameter(SortParameter.ItemTitle, SortParameter.Ascending);

            myQuery.AddSorting(sortParameter);

            string[] componentPresentationURIs = myQuery.ExecuteQuery();

            // Display query results
            ComponentPresentationFactory presentationFactory = new ComponentPresentationFactory(iPublicationID);

            // Create a ComponentPresentation to hold each presentation to be displayed in the loop
            ComponentPresentation cp = null;

            foreach (string componentPresentationURI in componentPresentationURIs)
            {
                //get the component presentation given the component URI and the component template ID
                cp = presentationFactory.GetComponentPresentation(componentPresentationURI, strComponentTemplateURI);

                if (cp != null)
                {
                    // The component presentation may not exist for the given component ID so check if it is null
                    Response.Write(cp.GetContent(true));
                }

            }
        }
    }
}