locked
Disable Dynamic Data Filter Dropdown without Disabling the Click Through Filtering RRS feed

  • Question

  • User-1927293304 posted

    I am disabling the dynamic filter dropdowns on some of the pages of my dynamic data app to improve performance (some of the tables are quite large).  I am doing it in the meta-data with the following:

    <Filter(Enabled:=False)>

    However, when I do this, it also disables the filtering that occurs when I click through from a foreign key.  Is there a good way to disable the dropdowns to save loading them without disabling the click through filtering?

    Thanks in advance

    Thursday, May 24, 2012 1:44 PM

Answers

  • User350138131 posted

    I'm doing something like this.

    [AttributeUsage(AttributeTargets.Property)]
    public class HideFilterInDefaultAttribute : Attribute
    {
    	public Boolean Hide { get; private set; }
    	public HideFilterInDefaultAttribute(Boolean hide)
    	{
    		Hide = hide;
    	}
    	// this will allow us to have a default set to false
    	public static HideFilterInDefaultAttribute Default = new HideFilterInDefaultAttribute(false);
    }
    public partial class ForeignKeyFilter : System.Web.DynamicData.QueryableFilterUserControl
    {
    	protected void Page_Init(object sender, EventArgs e)
    	{
    		string initialValue = DefaultValue;
    		if (initialValue == null && Column.Attributes.OfType<HideFilterInDefaultAttribute>().DefaultIfEmpty(HideFilterInDefaultAttribute.Default).First().Hide)
    		{
    			this.NamingContainer.Visible = false;
    		}
    		else
    		{
    			PopulateListControl(DropDownList1);
    			if (!String.IsNullOrEmpty(initialValue))
    			{
    				ListItem li = new ListItem();
    				li = DropDownList1.Items.FindByValue(initialValue);
    				DropDownList1.Items.Clear();
    				DropDownList1.Items.Add(li);
    			}
    		}
    	}
    }
    Northwind DB
    public class Product_MD
    {
    	[HideFilterInDefault(true)]
    	public object Supplier { get; set; }
    }
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 25, 2012 2:30 AM

All replies

  • User350138131 posted

    I'm doing something like this.

    [AttributeUsage(AttributeTargets.Property)]
    public class HideFilterInDefaultAttribute : Attribute
    {
    	public Boolean Hide { get; private set; }
    	public HideFilterInDefaultAttribute(Boolean hide)
    	{
    		Hide = hide;
    	}
    	// this will allow us to have a default set to false
    	public static HideFilterInDefaultAttribute Default = new HideFilterInDefaultAttribute(false);
    }
    public partial class ForeignKeyFilter : System.Web.DynamicData.QueryableFilterUserControl
    {
    	protected void Page_Init(object sender, EventArgs e)
    	{
    		string initialValue = DefaultValue;
    		if (initialValue == null && Column.Attributes.OfType<HideFilterInDefaultAttribute>().DefaultIfEmpty(HideFilterInDefaultAttribute.Default).First().Hide)
    		{
    			this.NamingContainer.Visible = false;
    		}
    		else
    		{
    			PopulateListControl(DropDownList1);
    			if (!String.IsNullOrEmpty(initialValue))
    			{
    				ListItem li = new ListItem();
    				li = DropDownList1.Items.FindByValue(initialValue);
    				DropDownList1.Items.Clear();
    				DropDownList1.Items.Add(li);
    			}
    		}
    	}
    }
    Northwind DB
    public class Product_MD
    {
    	[HideFilterInDefault(true)]
    	public object Supplier { get; set; }
    }
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 25, 2012 2:30 AM
  • User-1927293304 posted

    That worked really well, but it looks like the text next to the filter is still appearing.  What's the easiest way to suppress that too without modifying every PageTemplate?

    Thanks!

    Friday, May 25, 2012 3:44 PM
  • User-1927293304 posted

    Never mind, I changed

    Me.NamingContainer.Visible = False

    to

    Me.NamingContainer.NamingContainer.Visible = False

    and that seemed to do the trick.  thanks again!

    Friday, May 25, 2012 3:47 PM
  • User-330204900 posted

    you can also improve performance if you use the Autocomplete filter from my NuGet package Dynamic Data 15 Custom Filters you can set the number of characters the user must type before a prefiltered query is sent.

    Saturday, May 26, 2012 9:52 AM