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

Focus filteritem

1 Answer 26 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Kurt Bilde
Top achievements
Rank 2
Kurt Bilde asked on 31 Oct 2011, 10:56 AM

Hi,

 

I am using radfilter on a radlistview bound to a datasource. On pageload I use the following code to default show the filteritem Name from the datasource:

 

 

if (!IsPostBack)
{
       RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
       RadFilterPartner.FieldEditors.Add(editor);
       if (!IsPostBack)
       {
              editor.FieldName = "NAME";
              editor.DataType = typeof(string);
              RadFilterContainsFilterExpression filter = new RadFilterContainsFilterExpression("NAME");
              filter.Value = "";
 
              RadFilterPartner.RootGroup.Expressions.Add(filter);
        }
}
 

 

My question is how I can set the focus on the NAME filteritem on pageload, so the user can start typing the filtertext, instead of manually click the filteritem and then typing the filtertext?

-Kurt

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 31 Oct 2011, 05:04 PM
Hello Kurt Bilde,

Unfortunately the desired functionality is not supported with theRadFilter control.
Possible workaround in this case is to use the code below for setting the focus to the latest textbox:
protected void RadFilter1_PreRender(object sender, EventArgs e)
{
    var ctrl = ControlsOfType<ITextControl>(RadFilter1).Where(p => p.GetType() != typeof(LiteralControl));
    if (ctrl.Count() > 0)
        (ctrl.Last() as Control).Focus();
}
public IEnumerable<T> ControlsOfType<T>(Control parent) where T : class
{
    foreach (Control control in parent.Controls)
    {
        if (control is T)
        {
            yield return control as T;
            continue;
        }
        foreach (T descendant in ControlsOfType<T>(control))
        {
          yield return descendant;
        }
    }
}

I hope this works for you.

All the best,
Mira
the Telerik team
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 their blog feed now
Tags
Filter
Asked by
Kurt Bilde
Top achievements
Rank 2
Answers by
Mira
Telerik team
Share this question
or