locked
Cascading dropdownlists RRS feed

  • Question

  • User-326746839 posted

    Hi,

    Is there a simple example in showing how to make implementation of a 4 level cascading using dropdownlists inside an ASP.Net Dynamic data Entity C# form?

    I'm trying to say that I'd like to work with field filters (the details of parent-child a form, not the grid) those page's filters are located on top of your screens containing the grid by default and ----. I don't care about them

    To make a brief example I'd say this:

    Let's way that I'm entering addresses and I'd like to have available the following cascade: Country, State, City and County

    So if I choose Canada in the 1st dropdownlists I'd expect the second dropdownlist having: 
    Ontario, British Columbia, Nova Scotia, Manitoba, , Alberta, etc. 

    So if I had selected ONTARIO in the 2nd dropdwonlist the third dropdwonlists shoud have:  
    Toronto, Ottawa, Mississauga, Brampton, Hamilton, London, Markham, Vaughan, Kitchener, Windsor

    If I had chosen  Toronto in the third dropdwonlist I'd expect to have displyaed in the fourth dropdwonlists the following: 
    York, East York, Crescent Town, Thorncliffe Park, Weston, Oakwood–Vaughan, Etobicoke, Scarborough, North York, Mimico, Islington Willowdale, Newtonbrook and Downsview, Agincourt, Wexford and West Hill

    Monday, November 12, 2012 4:37 PM

Answers

  • User-330204900 posted

    Hi Carlos, I can give you a working sample if you can give me an example of your schema, there are twop different way I have implemented for this depending on the schema.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 13, 2012 6:47 AM
  • User-330204900 posted

    Hi Carlos, this will work fine withy my CascadeHierachical field template, I will work up a sample this weekend based on this database and e-mail it to you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 15, 2012 2:51 PM

All replies

  • User-330204900 posted

    Hi Carlos, I can give you a working sample if you can give me an example of your schema, there are twop different way I have implemented for this depending on the schema.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 13, 2012 6:47 AM
  • User-326746839 posted

    Thanks Anil for your answer BUT I can tell you that when it comes to ASP.Net Dynamic Data such approach doesn't even close resembles how Dynamic Data behaves .... you don't have controls available so you can work with them like in normal ASP.Net.

    Controls are created on the fly via templates so there is no way in implementing a solution like the one you're suggesting here

    Thanks anyway

    Carlos N. Porras
    (El Salvador) 

    Tuesday, November 13, 2012 5:54 PM
  • User-326746839 posted

    Hi Steve,

    Look at this short version of what is required

    if exists (select * from sys.foreign_keys where object_id = object_id('[Relationship1]') and OBJECTPROPERTY(object_id, 'IsForeignKey') = 1)

    Alter table [State] drop constraint [Relationship1]
    go
    if exists (select * from sys.foreign_keys where object_id = object_id('[Relationship2]') and OBJECTPROPERTY(object_id, 'IsForeignKey') = 1)
    Alter table [City] drop constraint [Relationship2]
    go
    if exists (select * from sys.foreign_keys where object_id = object_id('[Relationship3]') and OBJECTPROPERTY(object_id, 'IsForeignKey') = 1)
    Alter table [Address] drop constraint [Relationship3]
    go
    if exists (select * from sys.foreign_keys where object_id = object_id('[Relationship4]') and OBJECTPROPERTY(object_id, 'IsForeignKey') = 1)
    Alter table [Address] drop constraint [Relationship4]
    go


    if exists (select * from sys.tables where object_id = object_id('[Address]') and OBJECTPROPERTY(object_id, 'IsUserTable') = 1)
    Drop table [Address]
    go
    if exists (select * from sys.tables where object_id = object_id('[City]') and OBJECTPROPERTY(object_id, 'IsUserTable') = 1)
    Drop table [City]
    go
    if exists (select * from sys.tables where object_id = object_id('[Customer]') and OBJECTPROPERTY(object_id, 'IsUserTable') = 1)
    Drop table [Customer]
    go
    if exists (select * from sys.tables where object_id = object_id('[State]') and OBJECTPROPERTY(object_id, 'IsUserTable') = 1)
    Drop table [State]
    go
    if exists (select * from sys.tables where object_id = object_id('[Country]') and OBJECTPROPERTY(object_id, 'IsUserTable') = 1)
    Drop table [Country]
    go


    Create table [Country]
    (
    [cod_country] Numeric(18,0) Identity NOT NULL,
    [Country_name] Varchar(80) NULL,
    Constraint [pk_Country] Primary Key ([cod_country])
    )
    go

    Create table [State]
    (
    [cod_State] Numeric(18,0) Identity NOT NULL,
    [cod_country] Numeric(18,0) NOT NULL,
    [State_name] Varchar(80) NULL,
    Constraint [pk_State] Primary Key ([cod_State])
    )
    go

    Create table [Customer]
    (
    [cod_Customer] Numeric(18,0) Identity NOT NULL,
    [Customer_name] Varchar(80) NULL,
    Constraint [pk_Customer] Primary Key ([cod_Customer])
    )
    go

    Create table [City]
    (
    [cod_City] Numeric(18,0) Identity NOT NULL,
    [cod_State] Numeric(18,0) NOT NULL,
    [City_name] Varchar(80) NULL,
    Constraint [pk_City] Primary Key ([cod_City])
    )
    go

    Create table [Address]
    (
    [cod_Customer] Numeric(18,0) NOT NULL,
    [cod_Address] Numeric(18,0) Identity NOT NULL,
    [Address_Country] Varchar(80) NULL,
    [Address_state] Varchar(80) NULL,
    [Address_city] Varchar(80) NULL,
    [Address_street] Varchar(80) NULL,
    [Address_zip] Varchar(12) NULL,
    [cod_City] Numeric(18,0) NOT NULL,
    Constraint [pk_Address] Primary Key ([cod_Address])
    )
    go


    Alter table [State] add Constraint [Relationship1] foreign key([cod_country]) references [Country] ([cod_country]) on update no action on delete no action
    go
    Alter table [City] add Constraint [Relationship2] foreign key([cod_State]) references [State] ([cod_State]) on update no action on delete no action
    go
    Alter table [Address] add Constraint [Relationship3] foreign key([cod_Customer]) references [Customer] ([cod_Customer]) on update no action on delete no action
    go
    Alter table [Address] add Constraint [Relationship4] foreign key([cod_City]) references [City] ([cod_City]) on update no action on delete no action
    go


    Set quoted_identifier on
    go


    Set quoted_identifier off
    go

    Carlos N. Porras
    (El Salvador) 

    Tuesday, November 13, 2012 6:18 PM
  • User-1407477457 posted

    If I had chosen  Toronto in the third dropdwonlist I'd expect to have displyaed in the fourth dropdwonlists the following: 

    York, East York, Crescent Town, Thorncliffe Park, Weston, Oakwood–Vaughan, Etobicoke, Scarborough, North York, Mimico, Islington Willowdale, Newtonbrook and Downsview, Agincourt, Wexford and West Hill

    That's very granular.  Do you think your expected users will know the city in that much detail?

    Oh, by the way, those are neighbourhoods, not counties.

    Tuesday, November 13, 2012 8:03 PM
  • User3866881 posted

    Hello,

    If you wanna do a Cascading Dropdownlist, I think the sample given by MVP here is really very very nice, hope this helps;)

    http://csharpbits.notaclue.net/2009/01/dynamic-data-cascading-fieldtemplates.html

    Tuesday, November 13, 2012 8:31 PM
  • User-326746839 posted

    Hi Dan and thank you,

    by the way, this is just an example but I can certainly tell you that when it comes to put a little sense of what I am talking about here you should think in statistical terms.

    Maybe gettin this level of granularity might seem silly from your point of view as a person but if you were a company which sells houses, then it might be good for you to know (querying your database efficiently) that if you have what you call "neighbourhoods" alone inside its own field (not merged with the rest of your address) then you'll be capable of knowing how many houses do you7 have for instance in Weston, isn't it?

    Carlos N. Porras
    (El Salvador) 

    Wednesday, November 14, 2012 11:56 AM
  • User-326746839 posted

    Hi Mr. Dong,<o:p></o:p>

    I have tried in the past implementing that solution and I remember it works fine with 2 levels but if I'm not wrong the problem arises when you need to have some kind of complexity, let's say 5 nesting levels or more ... I'm not quite sure but I have that feeling right now<o:p></o:p>

    I have situations in which I need more than 7 dependency levels among the dropdownlist cascading<o:p></o:p>

    Maybe it could be trivial for you but this is really a nightmare for me as a developer because is something not easily achievable in real life situations. I was expecting, hoping and begging that this control could have come with this new release of VS2012 as an integral part of the standard package's features for ASP.Net Dynamic Data C# projects<o:p></o:p>

    Maybe you have never tried but in order to achieve proper cascading you must change your database design as to carry the parent keys all the way down to the child and lower level tables so you can see the upper levels in the required table that you're working with (I think you'll never understand what I’m saying here because you should have worked in real life situations doing and testing this) <o:p></o:p>

    Is a real nightmare ... at least for me it has been since I started working with ASP.Net Dynamic Data .... I think this might be the only serious piece of code missing in this technology or framework or tool or whatever its name might be<o:p></o:p>

    BUT I'M QUITE SERIOUS WHEN I SAY THAT THIS IS SOMETHING ON WHICH THE VS2012 DEVELOPMENT TEAM SHOULD HELPS US WITH THIS SITUATION AND PROVIDE A "CASCADING DROPDOWNLIST CONTROL" for as many levels as needed<o:p></o:p>

     <o:p></o:p>

    Carlos N. Porras
    (El Salvador) 

    Wednesday, November 14, 2012 12:14 PM
  • User-326746839 posted

    Hi Mr. Dong,

    The example doesn't work ...

    *******    must do some changes firts ... sorry !!!!

    Carlos N. Porras
    (El Salvador) 

    Wednesday, November 14, 2012 6:14 PM
  • User3866881 posted

    The example doesn't work ...

    Have you downloaded the example to have a test with?

    Wednesday, November 14, 2012 8:03 PM
  • User-326746839 posted

    Hi Steve and Mr. Dong,

    I have certainly made the example run. As I told you before, the solution works fine at 2 levels only. I tried before tryng to make my own implementation of the delegates that should be required to make the other levels to understand previous selections of the other dropdownlists but I had the difficulty of not knowing how to build the proper sentences in the populatexxxx() method (don't remember its exact name right now) because there is some kind of special libraries that should be used in order to build every new query but I just got stuck at that point so I abandoned the idea of going on with that effort.

    So I asked many times how to do some kind of reflection and things like that (I have talked with both of you before about this a couple of years ago) because there is no way (at least known for me) of "instantiating" a dropdownlist control already generated on the fly by Dynamic Data as to have access to all its properties and collect its data (the previously index selected by the user on that dropdownlist) 

    So, it seems I'm in ground zero agasin !!! 
    ...... UNLESS STEVE HELPS ME OUT THIS TIME.... ..... ..... .... ..... please ..... do it Steve !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Thursday, November 15, 2012 12:31 AM
  • User3866881 posted

    Hi again,

    Your problem seems to be a little strange and complicated……I've submitted this for futher deeply study on that.

    Thursday, November 15, 2012 12:49 AM
  • User-326746839 posted

    Hi Steve and Mr. Dong,

    I know you'll deliver what you promised me too, won't you?

    It seems that Steve has been out of focus these days ... 

    Mr. Dong: I know this is something rather trivial for someone who knows the inner workings, the inner devices of Dynamic Data. For someone who knows how this thing work this may as well be something trivial rather than something complex

    It is important to understand my example here: you just need to be able to create a dynamic cascade of dropdownlist which must obbey one simple criteria:

    AFTER SHOWING THE FIRST DROPDOWNLIST (THE ELDER OR THE MOST OLDEST ANCESTOR IN THE CHAIN OF DEPENDENCIES) ALL FOLLOWING DROPDOWNLISTS SHOULD BE SHOWN  ... ONE BY ONE ...  AS SOON AS ONE SELECTION HAS BEEN CHOSEN (SELECTED INDEX HAS CHANGED) FROM ITS PREVIOUS PARENT

    Or, if all of them are shown are shown at once, the dependant dropdownlists should display -Parent not chosen - (disabled) so you can make choices in proper order (top to bottom of the chain)


    I know for sure that this is something which must be truly simple for a Microsoft developer 

    Carlos N. Porras
    (El Salvador) 

    Thursday, November 15, 2012 12:13 PM
  • User-330204900 posted

    Hi Carlos, this will work fine withy my CascadeHierachical field template, I will work up a sample this weekend based on this database and e-mail it to you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 15, 2012 2:51 PM