Answered by:
Two addicion comboboxes in Dynamic Data

Question
-
User116907111 posted
Hello,
I have the following Problem. I have a combobox "one" with value Cars and a second combobox with the vaule carlines.
For Example. I want to select in combobox cars "Land Rover" than the second combobox should give me only cars from Land Rover like "Defender", "Range Rover" ...My Problem is that all Carlines are visible and all carlinetypes. I can select "Land Rover" but I doesn't get a filtered 2nd combobox. The second combobox give me all values that it gets like (Firebird, Trans Am, Golf, Polo, 525er, 725er .......)
How can I make a working filter on the combobox?
Thanks in advance for helping me out.
Regards,
BKThursday, September 11, 2008 11:35 AM
Answers
-
-
User-330204900 posted
You can make the change to the ExtractValues where I'm testing for make and model = 0 and then throwing an error.
protected override void ExtractValues(IOrderedDictionary dictionary) { int make; int model; int.TryParse(ddlMake.SelectedValue, out make); int.TryParse(ddlModel.SelectedValue, out model); if (make > 0 && model > 0) { var car = new CarType() { Make = make, Model = model }; dictionary[Column.Name] = car; } else { throw new ValidationException("You must select a valid Make and Model"); } }
Hope this helps [:D]
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 17, 2008 5:37 PM
All replies
-
User-330204900 posted
I think what you need (if this is NOT a filter issue) is my convertion of the Cascade Filter to a Fieltemplate here:
A Second Advanced FieldTemplate
Hope this helps [:D]
Thursday, September 11, 2008 12:54 PM -
User116907111 posted
Maybe that it could helps. I try to make this Northwind Example but it doesn't work out.
This step is not working:
Figure 4 - Order Details table
So we need to add some business logic to validate this before insert.
public partial class NWDataContext { partial void InsertOrder_Details(Order_Details instance) { var DC = new NWDataContext(); var dk = DC.Order_Details.SingleOrDefault( od => od.OrderID == instance.OrderID && od.ProductID == instance.ProductID ); if (dk != null) { // if a record is found throw an exception String error = "Duplicate Primary keys not allowed (OrderID={0} ProductID={1})"; throw new ValidationException(String.Format(error, instance.OrderID, instance.ProductID)); } else { // finnaly send to the database this.ExecuteDynamicInsert(instance); } } }
SingleOrDefault makes problems: Order_Details has no definition for "SingleOrDefault"
Friday, September 12, 2008 7:43 AM -
User-330204900 posted
Just change:
partial void InsertOrder_Details(Order_Details instance)
to
partial void InsertOrder_Details(Order_Detail instance)
Note Order_Details is now Order_Detail
Hope this helps [:D]
Friday, September 12, 2008 9:44 AM -
User116907111 posted
Hello again,
the Sample Northwind Project works. But I still have a Problem. My construct is not like the NW construct.
I have a Table qualification with "categorieID" and "speciallD". I have a table "categories" and a table "specials". And a 4th tabel called "categoieSpecial". This 4th table says that categorie "xy" has the specials "abc".I want to fill the qualification table and select both. (It is like Order_Details in NW) But I can't use the example because I can't link to the categorieSpez table.
Can you help me in that case?
TableA --> TableAB <-- TableB All to TableC (In Table C I will Select A and B which are filterd by TableAB) If I select A = "3" than B could only x,y or z ....
Regards,
BKMonday, September 15, 2008 7:29 AM -
User-330204900 posted
Hi BK, I sent you an e-mail asking for you to send a screen shot of your model or you could link it to here from say picasa.
Steve
Monday, September 15, 2008 8:25 AM -
User-330204900 posted
Here my interpritation of the diagram you sent me and the description of the relationship above.
From Blogger Pictures What you could do is add a custom FieldTemplate that knows about the other column (you can referance the entire entity via the row property of the FieldTemplate and cast the object to you entity type) and set a where clause in some Linq to SQL that pulls the list to populat the drop down box.
See my articles on Field Templates here:
- The Anatomy of a FieldTemplate.
- Your First FieldTemplate.
- An Advanced FieldTemplate.
- A Second Advanced FieldTemplate.
- An Advanced FieldTemplate with a GridView.
- An Advanced FieldTemplate with a DetailsView.
- An Advanced FieldTemplate with a GridView/DetailsView Project.
Hope this helps [:D]
Monday, September 15, 2008 12:59 PM -
User116907111 posted
I tried to make it like step 4.
My problem is that I doesn't know what I have to do in the partials.cs to make it working. (http://csharpbits.notaclue.net/2008/08/dynamic-data-and-field-templates-second.html) - Listing 6 – Finished ExtractValues and DataControl methodsYou see my database construct.Have you an idea what I must do in the Meta Data of bTableC? I have tried very much like that:
partial void InserttbTableC(bTableC instance)
{
var DC = new CDatDataContext();
var dk = DC.bTableC.SingleOrDefault(od => od.Id == instance.Id && od.B_Id == instance.B_Id);if (dk != null)
{
// if a record is found throw an exception
String error = "Duplicate Primary keys not allowed (Id={0} B_Id={1})";
throw new ValidationException(String.Format(error, instance.Id, instance.B_Id));
}
else
{
// finnaly send to the database
this.ExecuteDynamicInsert(instance);
}
}
*/}
/*
//bTableC MD
[MetadataType(typeof(bTableC_MD))]
public partial class bTableC
{
}
public class bTableC_MD
{
[Cascade("tbTableA")] // HERE I AM NOT SURE
[UIHint("Cascade")]
//public object tbTableB { get; set; }
public object tbTableAB { get; set; }
}
public partial class tbTableAB { }
*/Monday, September 15, 2008 1:25 PM -
User-330204900 posted
Hi BK, the cascade I converted from the DD Future Filter will not work in you case as it expects a direct link to the FK not via a M:N releationship.
So what I recoment is reate you own FieldTemplate that knows about the entity type so you then use some Linq to SQL to populate the dropdownList with Name and SPEZ_Key and a where somthing like below:
In the OnDataBinding event of the FieldTemplate you could add some code like:
// you know that the row type here is Product because // you only set this UIHint on type of Product var product = Row as Product; var DC = new NWDataContext(); var list = from c in DC.Categories where c.CategoryID == product.CategoryID select new { Id = c.CategoryID, Name = c.CategoryName }; DropDownList1.DataSource = list; DropDownList1.DataValueField = "Id"; DropDownList1.DataTextField = "Name"; DropDownList1.DataBind();
with this you can then reach across you M:N relationship and get the data you want.
Hope this helps [:D]
Monday, September 15, 2008 1:47 PM -
User116907111 posted
Hello again,I have tried so much but I don't get it work.
1. I made a copy of ForeignKey_Edit.ascx. Rename it to: DropdownForeignKey_Edit.ascx
2. I Rename the Inherits to "DropdownForeignKey_EditField"
3. I make many tests with the OnDataBinding like that:
protected override void OnDataBinding(EventArgs e)
{
var jobspecial = Row as tbJobcodeSpezialisierung;var DC = new CRMDatenDataContext();
var list = from s in DC.tbSpezialisierung
where s.SPEZ_Key == jobspecial.SPEZ_Key
select new { Id = s.SPEZ_Key, Name = s.SpezialisierungBezeichnung };DropDownList1.DataSource = list;
DropDownList1.DataValueField = "Id";
DropDownList1.DataTextField = "Name";
DropDownList1.DataBind();
}4. I wrote in partials.cs that code:
//Qualifikation2 MD
[MetadataType(typeof(Qualifikation2_MD))]
public partial class tbQualifikation2
{}
public class Qualifikation2_MD
{
[UIHint("DropdownForeignKey_Edit")]
public object SPEZ_Key { get; set; }
}But I don't know how the filter might be work because I can only select on table and not more. But my problem is that I can't load the insert page because errors like "SPEZ_Key is no foreingn Key and can't be used here" shows up.
I searched a lot. But I never can find a m:n example like my model. I always find 1:n .... But that doesn't hepl me...
Regards,
BKTuesday, September 16, 2008 8:05 AM -
User-330204900 posted
Hi BK, is SPEZ_key a Foreign Key column? As I'm just going to setup some tables in a similar way to yours to test this out.
Tuesday, September 16, 2008 10:59 AM -
User116907111 posted
Yes it is. I've send you a picture of the field types of the tables.
Tuesday, September 16, 2008 11:34 AM -
User-330204900 posted
Thanks I'll get on to it tonight [;)]
Tuesday, September 16, 2008 1:17 PM -
User116907111 posted
Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>do you have any ideas for my problem? I work since 3 days on it and nothing works.
I think it can’t be that difficult. I think the syntax for the combobox might be like that in Ondatabinding:
<o:p></o:p>CDatDataContext DC = new CDatDataContext ();<o:p></o:p>
var Daten = from jc in DC.tbTableA
from jcsp in DC.tbTableAB
where jcsp.A_Id == jc.Id
from spez in DC.tbTableB
where spez.Id == jcsp.B_Idselect new { Id = spez.Id, Name = spez.Bezeichnung};
DropDownList1.DataSource = Daten;<o:p></o:p>
DropDownList1.DataValueField = "Id";<o:p></o:p>
DropDownList1.DataTextField = "Name";<o:p></o:p>
DropDownList1.DataBind();
<o:p></o:p>But I find out one more Problem:
If I say in the partials.cs that a field must be a FieldTemplate that doesn’t work for the Insert and Edit.aspx. It only works for the List.aspx. Why? What is wrong?
<o:p></o:p>[UIHint("DropdownForeignKey_Edit")]
<o:p></o:p>public object B_Id { get; set; }<o:p></o:p>It tested all FieldTemplates. Only the FieldTemplate “Boolean” works in the Insert/Edit.aspx Page. All others will be a standard TextBox. What is wrong with that?
Regards,
BK<o:p></o:p>Wednesday, September 17, 2008 5:55 AM -
User-330204900 posted
Hi BK, I'm working on it now thae main issues is it requires postback of the fist DDList before the Second DDList can be populated. This applies to insert and Edit modes. I sould get back to you later today with a working sample [:D]
steve
Wednesday, September 17, 2008 7:10 AM -
-
User116907111 posted
What can I tell you. That is a very great sample that you made. It is fantastic. There is a little thing that I must change. In Table C the A_Id and B_Id could be null. That is the case if someone want say: "Jaguar but I don't know the Carline" or "Car but I don't know Mark and Carline". Fields should not be null but some people want fill that information later and so that is needed.
The change is working to 80%. I can say. New Insert in C with null. But Update on it runs an error. (Maybe I will use here the override updatetablec function...?)
But anyway. That was a great sample. I will implement that!!!
Thank you very much!
Regards,
BKWednesday, September 17, 2008 4:58 PM -
User-330204900 posted
You can make the change to the ExtractValues where I'm testing for make and model = 0 and then throwing an error.
protected override void ExtractValues(IOrderedDictionary dictionary) { int make; int model; int.TryParse(ddlMake.SelectedValue, out make); int.TryParse(ddlModel.SelectedValue, out model); if (make > 0 && model > 0) { var car = new CarType() { Make = make, Model = model }; dictionary[Column.Name] = car; } else { throw new ValidationException("You must select a valid Make and Model"); } }
Hope this helps [:D]
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 17, 2008 5:37 PM -
User116907111 posted
Yes it helps. I'm work on that.
Thanks.
Wednesday, September 17, 2008 5:45 PM