2

I have a devexpress gridview within my asp.net page which has a filter row. The built-in feature needs me to filter the from the first letters not the letters in between.

So "Sa" would find "Samuel" but not "Uncle Sam". To search using for the "Uncle Sam", I need to use %sa%. My clients don't want that.

I found a solution that requires me to use Settings-AutoFilterCondition="Contains" for every field in the gridview. I have more than 20s gridview in the asp.net program.

Is there any alternatives to set the default for all gridview at once?

Thanks

bose
  • 21
  • 1
  • 3

3 Answers3

2

I would suggest that you create a new ASP.NET theme based on the existing ones and change this property in a skin file. In this case, you will receive the required result for the whole web site without changing even a line of code :)

platon
  • 5,310
  • 1
  • 22
  • 24
1

You can set it in the PageLoad event of the code behind like this:

[VB.NET]
Protected Sub Page_Load(sender As Object, e As EventArgs)
    For Each col As GridViewDataColumn In grid.Columns
        col.Settings.AutoFilterCondition = AutoFilterCondition.Contains
    Next
End Sub
Mehul
  • 848
  • 4
  • 13
  • That is an improvement for large grids but if I understand correctly he is looking to do this site wide. So for every grid on every page. Which would be useful. – bendemes Jan 24 '12 at 15:58
  • Good point, I recommend taking a look at Platon's comment below about creating a new theme. This would solve it easily for the whole site. – Mehul Jan 30 '12 at 22:18
  • I don't see Platon's comment? But I will give themes a go when I get round to it. – bendemes Feb 01 '12 at 12:52
0

I achieved this the following way:

  1. Added the following extension method to cut down the work, it returns all controls of a type:

    public static IEnumerable<T> GetAllControlsOfType<T>(this Control parent) where T : Control
    {
        var result = new List<T>();
        foreach (Control control in parent.Controls)
        {
            if (control is T)
            {
                result.Add((T)control);
            }
            if (control.HasControls())
            {
                result.AddRange(control.GetAllControlsOfType<T>());
            }
        }
        return result;
    }
    
  2. Add the following to my basepage OnLoad Event (which inherits from page, and all my pages inherit from), if you don't use a base page I recommend it, otherwise you could add it to each page.

       this.GetAllControlsOfType<ASPxGridView>()
        .SelectMany(gv => gv.Columns.OfType<GridViewDataTextColumn>())
        .ForEach(c => c.Settings.AutoFilterCondition = AutoFilterCondition.Contains);
    
Squid
  • 4,560
  • 1
  • 12
  • 8