RadFilter on RadListBox

6 posts, 0 answers
  1. Henry
    Henry avatar
    14 posts
    Member since:
    Dec 2008

    Posted 14 Mar 2014 Link to this post

    Hi,

    I think I might just be a little confused but I cannot get the above combination to work.

    I have a RadListBox. I have an Array of objects that I bind using the "DataSource" attribute. I set this programmatically. I also set the "DataTextField", the "DataValueField" and the call the "DataBind" method.

    I have created a Filter field on the RadFilter in the designer and set the "FieldName" value to be the same as the "DataTextField" from the RadListBox. I then programmatically, after I have called the "DataBind" on the RadListBox, set the "DataSourceControlID" to the ID of the RadListBox.

    This is done on a user control using .net 3.5. As soon as I test the page that contains the control, I get an "Object not set to an instance of an object" error, with the following stack trace:

    ​[NullReferenceException: Object reference not set to an instance of an object.]
       System.Object.GetType() +0
       Telerik.Web.UI.RadFilterDataSourceHelper.<.cctor>b__26(String eventName, MethodInfo eventHandler, RadFilter filterInstance, IDataSource dataSourceInstance) +76
       Telerik.Web.UI.RadFilter.AttachToDataSource() +210
       Telerik.Web.UI.RadFilter.OnLoad(EventArgs e) +723
       System.Web.UI.Control.LoadRecursive() +66
       System.Web.UI.Control.LoadRecursive() +191
       System.Web.UI.Control.LoadRecursive() +191
       System.Web.UI.Control.LoadRecursive() +191
       System.Web.UI.Control.LoadRecursive() +191
       System.Web.UI.Control.LoadRecursive() +191
       System.Web.UI.Control.LoadRecursive() +191

    Any idea on this please, or exactly how I need to get the two to work together. I've looked at the documentation but is extremely helpful enough.

    Regards,

    Henry
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Mar 2014 in reply to Henry Link to this post

    Hi Henry,

    Please have a look into the sample code snippet to achieve your scenario.

    ASPX:
    <telerik:RadFilter runat="server" ID="RadFilter1">
    </telerik:RadFilter>
    <telerik:RadListBox runat="server" ID="RadListBox1" Height="200px" Width="250px">
    </telerik:RadListBox>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadListBox1.DataSourceID = "SqlDataSource1";
        RadListBox1.DataTextField = "Name";
        RadListBox1.DataValueField = "ID";
        RadListBox1.DataBind();
        RadFilter1.DataSourceControlID = "SqlDataSource1";
        
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Henry
    Henry avatar
    14 posts
    Member since:
    Dec 2008

    Posted 25 Apr 2014 in reply to Shinu Link to this post

    Hi Shinu,

    Thanks for the reply. But I use a locally populated array of objects and set the RadList1.DataSource property to my array.

    How would your example be changed to facilitate that?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Apr 2014 in reply to Henry Link to this post

    Hi Henry,

    Please do the following modifications in the above posted code which works fine at my end.

    C#:
    public class ArrayListItems
    {
        private string itemName;
        public ArrayListItems(string item)
        {
            ItemName = item;
        }
        public string ItemName
        {
            get { return itemName; }
            set { itemName = value; }
        }
    }
    private ArrayList theCart()
    {
        ArrayList list = new ArrayList();
        list.Add(new ArrayListItems("Diamond"));
        list.Add(new ArrayListItems("Ruby"));
        list.Add(new ArrayListItems("Sapphire"));
        return list;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ArrayList list = theCart();
        RadListBox1.DataSource = list;
        RadListBox1.DataTextField = "ItemName";
        RadListBox1.DataBind();
        RadFilter1.DataSourceControlID = "SqlDataSource1";
    }

    Thanks,
    Shinu.
  6. Henry
    Henry avatar
    14 posts
    Member since:
    Dec 2008

    Posted 02 May 2014 in reply to Shinu Link to this post

    Hi Shinu,

    What does "RadFilter1.DataSourceControlID = "SqlDataSource1";" refer to. There is no "SqlDataSource1".

    Regards,

    Henry
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 May 2014 in reply to Henry Link to this post

    Hi Henry,

    I apologize for giving you the wrong code in the above post. RadFilter doesn't have DataSource property, so it is not possible to set ArrayList as the DataSource for the RadFilter. One suggestion is that you can set the DataSourceID of RadFilter and RadListBox from the ASPX itself like this demo. Another suggestion is that you can create Custom Field Editors.

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017