More in this section

Forums / Developing with Sitefinity / Databinding not working on NewsView

Databinding not working on NewsView

2 posts, 0 answered
  1. Chris Warner
    Chris Warner avatar
    12 posts
    12 Oct 2009
    15 Oct 2009
    Link to this post
    Hi again guys/girls

    Just come accross another strange thing while trying to do custom data binding on a news view

    Here is the HTML and code for the usercontrol

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="SampleControl.ascx.cs" Inherits="UserControls_SampleControl" %> 
    <%@ Register Assembly="Telerik.News" Namespace="Telerik.News.WebControls" TagPrefix="tel" %> 
    <asp:CheckBox runat="server" Text="Filter tc" ID="filterTCCheckBox" /> 
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
    <tel:NewsView runat="server" ID="newsView1" /> 

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System; 
    using System.ComponentModel; 
    using Telerik.Cms.Engine; 
    using Telerik.News; 
    using System.Collections; 
    public partial class UserControls_SampleControl : System.Web.UI.UserControl 
        string exp = string.Empty; 
        protected void Page_Load(object sender, EventArgs e) 
        private void setFilter() 
            ContentManager manager = new ContentManager("News"); 
            IMetaSearchInfo[] filter = new IMetaSearchInfo[] { new MetaSearchInfo(MetaValueTypes.ShortText, "Category""Latest Developments")  
                } ; 
            IList listofItems = manager.GetContent(filter); 
            newsView1.CustomDataSource = listofItems; 
        protected void Button1_Click(object sender, EventArgs e) 

    I can confirm that the category "Latest Developments" has two news items in it and the IList listOfItems contains two items however no items are rendered.

    Any Ideas?

    Thanks in advance

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    16 Oct 2009
    Link to this post
    Hello Chris Warner,

    Try using the following approach.

        protected void Page_Load(object sender, EventArgs e)
    public void CustomDataSource()
            ContentFilterBuilder filter = new ContentFilterBuilder(NewsView1);
            filter.AddFilter(new ContentFilterStatement("Category", "CatName", ContentFilter.Condition.Equal));

    It does not make sense to create a filter, then call GetContent, create a new datasource and then bind the control.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered