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
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,
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
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)
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.
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
Member
5 Points
44 Posts
Filter on dropdown in the Entity Template
Dec 01, 2010 10:01 AM|lahoriboy|LINK
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
All-Star
17916 Points
5681 Posts
MVP
Re: Filter on dropdown in the Entity Template
Dec 01, 2010 07:33 PM|sjnaughton|LINK
Hi Osman, see my articles here
Dynamic Data 4
Always seeking an elegant solution.
Member
5 Points
44 Posts
Re: Filter on dropdown in the Entity Template
Dec 07, 2010 09:13 AM|lahoriboy|LINK
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
All-Star
17916 Points
5681 Posts
MVP
Re: Filter on dropdown in the Entity Template
Dec 07, 2010 09:23 AM|sjnaughton|LINK
Hi Osman, did you test the sample project attached to the article?
Dynamic Data 4
Always seeking an elegant solution.
Member
5 Points
44 Posts
Re: Filter on dropdown in the Entity Template
Dec 07, 2010 10:29 AM|lahoriboy|LINK
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
All-Star
17916 Points
5681 Posts
MVP
Re: Filter on dropdown in the Entity Template
Dec 07, 2010 10:54 AM|sjnaughton|LINK
Hi Osman, it's a good solution for simple filtering.
Dynamic Data 4
Always seeking an elegant solution.
Member
5 Points
44 Posts
Re: Filter on dropdown in the Entity Template
Dec 07, 2010 02:23 PM|lahoriboy|LINK
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
None
0 Points
9 Posts
Re: Filter on dropdown in the Entity Template
Jul 30, 2012 03:39 PM|bja58|LINK
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.
Member
71 Points
48 Posts
Re: Filter on dropdown in the Entity Template
Jul 31, 2012 02:45 AM|valZ|LINK
I decide this problem in such a way.
For Page.GetFilterValuesFromSession see Sjnaughton`s excelent article
http://csharpbits.notaclue.net/2010/12/filter-history-for-dynamic-data-4.html
Hope this helps.