locked
FK detail dropdownlist RRS feed

  • Question

  • User-1506742489 posted

     i have a 3 tables, Rep which has a RepID as primary key, Site which has SiteID as Primary Key and RepID as an FK, Event which has EventID as Primary Key and SiteID as FK and RepID as FK.  When Inserting/Editing Event the DropDownList for Site contains all of the sites, not just the ones belonging to the RepID of the current Event and the same for the Sites, all of them are there, not just the ones for the current Rep.

    I'm guessing this is because the RepID is not on the URL line so Dynamic Data does not know about it.

    It seems like there should be an attribute somewhere that I can decorate the partial class or class with that I am missing...

    Thanx,

    G

    Tuesday, September 23, 2008 12:31 PM

All replies

  • User-330204900 posted

    Hi Grayaid, have a look at my blog and in particular A Second Advanced FieldTemplate which has a cascade ForeignKey FieldTemplate that allows you to filter based on a second FK, you may be able to modify it to suit your needs.

    Or try this

    DD_FT_MtoNcustom.zip

    This is a FieldTemplate I created to do something silmilar(Note the DB is in SQL 2008)

    Hope this helps [:D]

    Tuesday, September 23, 2008 1:24 PM
  • User-1506742489 posted

     Steve,

    Thanx, I was avoiding modifying your Second Advanced  Field Template hoping that there was something I was missing.  :-)

    So now i am heading in that direction, thanx for your fine work and kind assistance!

    G

    Tuesday, September 23, 2008 2:09 PM
  • User-1506742489 posted

    Steve,

    I thought I had it ;-)  but am getting an FK error: 'RepresentativeID' is not a foreign key column and cannot be used here.

    This happens in Cascade.ascx.cs:GetDisplayString() function on the ForeignKeyColumn itself when i try to go to the MeetingEvents from the MeetingSites or from Representatives.

    MeetingEvent table has a primary key - SeqNo (int Identity) as do the other tables.

    MeetingEvent has a FK RepresentativeID to Representative, and a FK SiteID to MeetingSite.

    The Class is as follows:

    [MetadataType(typeof(MetadataMeetingEvent))]

    public partial class MeetingEvent

    {

    }

     

    [
    DisplayColumn( "MeetingDT", "MeetingDT", false )]

    public class MetadataMeetingEvent

    {

    public object SeqNo { get; set; }

    [Cascade("Representative")]

    [UIHint("Cascade")]

    public object RepresentativeID { get; set; }

    [Cascade( "MeetingSite" )]

    [UIHint( "Cascade" )]

    public object SiteID { get; set; }

    [DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]

    public object MeetingDT { get; set; }

    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:t}")]

    public object MeetingTime { get; set; }

     

    Thanx,

    G

    Tuesday, September 23, 2008 3:06 PM
  • User-1506742489 posted

    Hmmm..

    There is also an underlying error on TargetSite-DeclaringType-GenericParameterAttributes of {"Method may only be called on a Type for which Type.IsGenericParameter is true."}

    Which doesn't mean anything to me though....

    G

    Tuesday, September 23, 2008 3:33 PM
  • User-1506742489 posted

    Steve,

    Does my Parent table column name have to be the same as the FK column name in the detail table?

    Currently:
    Representative

        SeqNo

        NameLast

        NameFirst

        ...

    MeetingEvent

        SeqNo

        RepresentativeID               which is a FK to Representative.SeqNo

        SiteID                               which is a FK to MeetingSite.SeqNo

     

    and maybe that is my problem..

     

    Help!

    G

    Tuesday, September 23, 2008 3:50 PM
  • User-330204900 posted

    Have a look at DD_FT_MtoNcustom.zip  this may be more what you want.

    Tuesday, September 23, 2008 4:26 PM