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

RadFilterDropDownEditor Dynamic DataSource

6 Answers 187 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Jannis
Top achievements
Rank 1
Jannis asked on 21 Oct 2013, 10:15 AM
Hi,

I have a application where i created a custom RadFilter with Dropdown like explained in
http://www.telerik.com/help/aspnet-ajax/filter-custom-editors.html
I set the DataSource dynamically in the code be for each field it is different.
This was working perfectly fine under version 2013.1.417

Now i updated to a newer release and it is not working any more.
The dropdown lists are empty and it is looking like in the attached image.

In the new release there is a build-in RadFilterDropDownEditor class.
It is pretty nice but it seems that there is no functionality to set the DataSource dynamically.
There is just the option to specify the DataSourceID.

Can someone help me how to solve the problem?

Best regards

6 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 24 Oct 2013, 08:12 AM
Hello Jannis,

Generally such type of problems may occur when the name of the custom field editor class matches that of the built-in one. If that is the case I would recommend modifying the class name in order to avoid conflicts thus resolving the problem.

As for assigning a DataSourceID to the built-in editor this is achievable by subscribing to the FieldEditorCreated event of the RadFilter as demonstrated below:
protected void RadFilter1_FieldEditorCreated(object sender, RadFilterFieldEditorCreatedEventArgs e)
    {
        RadFilterDropDownEditor dropDownEditor = (e.Editor as RadFilterDropDownEditor);
        if (dropDownEditor != null)
        {
            dropDownEditor.DataSourceID = "SqlDataSource1";
        }
    }


Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jannis
Top achievements
Rank 1
answered on 25 Oct 2013, 08:28 AM
Hello Angel,

No it is not the case.
The name of my custom field editor class is different.

No thats exactly the point.
I dont want to set the DataSourceID
but specify a DataTable dynamically.

So i have the following function like in
http://www.telerik.com/help/aspnet-ajax/filter-custom-editors.html
public DataTable GetDataTable(string query)
{
    String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand(query, conn);
  
    DataTable myDataTable = new DataTable();
  
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
  
    return myDataTable;
}


And i want to do somthing like
private void Page_Init()
{
    // clear editors
    RadFilterTemp.FieldEditors.Clear();           
      
      
    foreach (int i = 1; i < 50; i++)
    {
        CustomRadFilterDropDownEditor tmp_drop_down_field = new CustomRadFilterDropDownEditor();
        tmp_drop_down_field.DisplayName = "Name_" + i;
        tmp_drop_down_field.FieldName = "Name_" + i;
        tmp_drop_down_field.DataSource = GetDataTable("SELECT * FROM WhatEver WHERE ID=" + i);
        tmp_drop_down_field.DataTextField = "DisplayText";
        tmp_drop_down_field.DataValueField = "Value";
         
        RadFilterTemp.FieldEditors.Add(tmp_drop_down_field);
    }
}
Thats the code for the custom field editor.
You can think about doing that as well with the build-in editor.

But it seems that the build in is not providing this feature.
And with releases newer than 2013.1.417 (i tested with the new Q3 2013 now) the custom approach is also not working because the dropdown boxes appear empty like in the screenshot i provided with the first post.

Can you help me?

Best regards
Jannis
0
Angel Petrov
Telerik team
answered on 30 Oct 2013, 08:31 AM
Hi Jannis,

Generally you should be able to dynamically populate both the built-in editor and the custom one. To demonstrate a possible realization of the first scenario I have assembled a website for you to review. In the example the drop down is being populated in the ExpressionItemCreated event.

As for the custom editor it would be hard to tell what is causing the unwanted behavior without having a better understanding of the implementation. That said I would like to ask you to provide us with a small runnable sample which we can debug locally.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jannis
Top achievements
Rank 1
answered on 06 Nov 2013, 12:16 PM
Thanks for your reply.

I don't know where the problem actually was, but after reimplementing the custom filter it worked,
Although it was the the same code.

By the way i did not use the build-in editor but a custom one.

Thanks a lot.
Best regards
0
Angelico
Top achievements
Rank 1
answered on 19 Jan 2014, 03:29 PM
Hi Angel, Im using radfilterdropdowneditor in my application. How do you bind a datasource using a List / Dictionary.? my goal is to have a true or false dropdown. Pls Help me. Thank you. Anjo
0
Angel Petrov
Telerik team
answered on 22 Jan 2014, 03:52 PM
Hello Anjo,

For achieving this goal you can subscribe to the OnExpressionItemCreated event and assigning the List as a datasource of the RadDropDownList. A demonstration of this is available in the project attached in my previous post.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Filter
Asked by
Jannis
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Jannis
Top achievements
Rank 1
Angelico
Top achievements
Rank 1
Share this question
or