locked
Filter on dropdown in the Entity Template RRS feed

  • Question

  • User261226050 posted

    Hi,

                I have a db with tables like Accounts, Clients and ClientContacts, Locations. Each Client has multiple locations. Also, ClientContacts are linked to a Location. Now, on the ClientContact edit/detail page. It shows drop down for locations, showing all locations. I would like to Filter the dropdown. I would like to show only those locations that are linked to the client of the contact. How would i do that in DD. Looking for advice. Thanks,

     Regards,

     Osman 

    Note : this is different form the list page issue which can be fixed with Filter but here you are only using DynamicControl

    Wednesday, December 1, 2010 10:01 AM

All replies

  • User261226050 posted

    Hi,

               I tried the solution. it was a quick try and it did not work. The error was  that the Location table does not have the ClientContactID. Well, i looked at the sample schema you were using and my schema does not match it. See the schema again :

    Client has many Locations

    Client has many ClientContacts

    Each ClientContact has a Location

                           what i want to do is just filter the list on the edit page so we can select from only location that belong to the Client. What solution do you propose ? Let me know the details. Thanks,

    Regards,

    Osman 

    Tuesday, December 7, 2010 9:13 AM
  • User-330204900 posted

    Hi Osman, did you test the sample project attached to the article? 

    Tuesday, December 7, 2010 9:23 AM
  • User261226050 posted

    Yes, partially. Like i said the schema does not match. I used the Cascade attribute in my own project and it failed because the relationship does not exist.

                  It is not multiple levels of simple many-to-many. Please see the schema again.

                 what i am thinking is to pupulate the dropdown with just locations for the client. I saw your other post

    http://forums.asp.net/p/1495272/3523789.aspx

                  Probably thats what i am going to do. what do you think ?

    Regards,

    Osman 

    Tuesday, December 7, 2010 10:29 AM
  • User-330204900 posted

    Hi Osman, it's a good solution for simple filtering. 

    Tuesday, December 7, 2010 10:54 AM
  • User261226050 posted

    Hi,

               I even wanted to try but i got stuck again. As its a cascade dropdownlist so i need to get the value of other dropdownlist selected value on the page. How do you do that ? get value of another control ?

               I serious think that i should not do that in the foreign key field template instead i should build a custom filter. Woud you be able to quickly make some changes and build a custom version of the cascade control that would work for senarios like mine, the schema is similar to mine ?

              Additionally, the control should be able to set values for multiple fields as the cascade dropdowns, i need to set all the values not just one value, Right ? (how would we do it as the attributes are applied to one field or both or what)

              Thanks,

    Regards,

    Osman

    Tuesday, December 7, 2010 2:23 PM
  • User-635256440 posted

    Lahoriboy:  did you ever figure out how to do this?  I have a similar question and can't find a working solution.  Any help you can offer would be appreciated.

    Monday, July 30, 2012 3:39 PM
  • User350138131 posted

    i need to get the value of other dropdownlist selected value on the page

     

    I decide this problem in such a way.

    //public partial class ForeignKeyFilter : System.Web.DynamicData.QueryableFilterUserControl {
    public partial class ForeignKey_EditField : System.Web.DynamicData.FieldTemplateUserControl{
    	protected void Page_Init(object sender, EventArgs e) {
    		if (!IsPostBack) {
    			System.Reflection.MethodInfo method;
    			Type dct = Column.Table.DataContextType;
    			method = dct.GetMethod("POPUP_" + ((MetaForeignKeyColumn)Column).ParentTable.EntityType.Name);
    			IQueryable ret = null;
    			if (method != null) {
    				System.Reflection.ConstructorInfo constuct = dct.GetConstructor(new Type[] { });
    				DataContext db = (DataContext)constuct.Invoke(null);
    				Type tp = (Type)((object[])Global.AppModels[Context.GetCurrentModel()])[0];
    				object[] prm = new object[] { listControl, Column.Table};
    				ret = (IQueryable)method.Invoke(db, prm);
    			}
    			if (method == null || ret == null)
    				PopulateListControl(listControl);
    		}
    	}
    }
    public partial class YourDataContext {
    	public object POPUP_Location(object lst1, MetaTable table) {
    		// MetaTable table is a ClientContact table
    		Dictionary<String, Object> fiterValues=((Control)lst1).Page.GetFilterValuesFromSession(table, null);
    		string columnValue = fiterValues["clientContactId"].ToString(); // for example
    		var query = (from t in this.Locations
    					 where String.IsNullOrEmpty(coumnValue) || t.clientContactId == columnValue
    					 select new {
    						 id = t.locationId,
    						 txt = t.locationName
    					 }
    		);
    		foreach (var gr in query) {
    			((ListControl)lst1).Items.Add(new ListItem(gr.txt, gr.id));
    		}
    		return query;
    	}
    }

    For Page.GetFilterValuesFromSession see Sjnaughton`s excelent article

    http://csharpbits.notaclue.net/2010/12/filter-history-for-dynamic-data-4.html

    Hope this helps.

    Tuesday, July 31, 2012 2:45 AM