This is a migrated thread and some comments may be shown as answers.

RadFilter on RadListBox

5 Answers 155 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Henry
Top achievements
Rank 2
Henry asked on 14 Mar 2014, 08:08 AM
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

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Mar 2014, 12:12 PM
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.
0
Henry
Top achievements
Rank 2
answered on 25 Apr 2014, 12:16 PM
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?
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2014, 06:41 AM
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.
0
Henry
Top achievements
Rank 2
answered on 02 May 2014, 08:12 AM
Hi Shinu,

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

Regards,

Henry
0
Shinu
Top achievements
Rank 2
answered on 02 May 2014, 09:43 AM
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.
Tags
Filter
Asked by
Henry
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Henry
Top achievements
Rank 2
Share this question
or