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

Filter Function StartsWith

1 Answer 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JustinWong
Top achievements
Rank 1
JustinWong asked on 14 Dec 2010, 12:42 AM
Hi Friends:

In a grid column, I have:  CurrentFilterFunction="StartsWith" and AutoPostBackOnFilter="true" and ShowFilterIcon="false" .  The idea is when user press the enter key, after typing in something in the filter text box, a search using 'StartsWith' will proceed.

This works For as long as there is something typed in the search box.  If the user removes the text and press enters, all the records are returned - which is as expected.

But here's the problem:  Now, the user type in something, say 'Ak' in the search box and press enter, the filter function has changed:  It now defaults to 'Contains' instead of 'StartsWith' 

Is there a way to make sure that with the above scenario, the filter function is ALWAYS 'StartsWith' and nothing else?

Thanks

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 15 Dec 2010, 09:08 AM
Hi Justin,

The auto-postback filtering of RadGrid is designed to work with the Contains function indeed. However, you can easily circumvent this limitation by attaching an event handler to grid's ItemCommand event, check if a filtering command is coming in, inspect the CommandArgument property of the event args object (e.CommandArgument - it will be of type Pair) and replace its First object with the StartsWith keyword.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        ((Pair)e.CommandArgument).First = "StartsWith";
    }
}


Hope it helps.

All the best,
Tsvetoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
JustinWong
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or