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
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.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
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
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
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.
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?
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
I have situations in which I need more than 7 dependency levels among the dropdownlist cascading
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
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)
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
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
klca
Member
507 Points
411 Posts
Cascading dropdownlists
Nov 12, 2012 08:37 PM|LINK
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
anil.india
Contributor
2613 Points
453 Posts
Re: Cascading dropdownlists
Nov 13, 2012 06:17 AM|LINK
refer Mikes article on this http://www.mikesdotnetting.com/Article/97/Cascading-DropDownLists-with-jQuery-and-ASP.NET
You can also refer - http://csharpdotnetfreak.blogspot.com/2009/03/populate-dropdown-based-selection-other.html
codepattern.net/blog ||@AnilAwadh
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Cascading dropdownlists
Nov 13, 2012 10:47 AM|LINK
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.
Always seeking an elegant solution.
klca
Member
507 Points
411 Posts
Re: Cascading dropdownlists
Nov 13, 2012 09:54 PM|LINK
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)
klca
Member
507 Points
411 Posts
Re: Cascading dropdownlists
Nov 13, 2012 10:18 PM|LINK
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)
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Cascading dropdownlists
Nov 14, 2012 12:03 AM|LINK
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.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Cascading dropdownlists
Nov 14, 2012 12:31 AM|LINK
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
klca
Member
507 Points
411 Posts
Re: Cascading dropdownlists
Nov 14, 2012 03:56 PM|LINK
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)
klca
Member
507 Points
411 Posts
Re: Cascading dropdownlists
Nov 14, 2012 04:14 PM|LINK
Hi Mr. Dong,
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
I have situations in which I need more than 7 dependency levels among the dropdownlist cascading
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
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)
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
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
Carlos N. Porras
(El Salvador)
klca
Member
507 Points
411 Posts
Re: Cascading dropdownlists
Nov 14, 2012 10:14 PM|LINK
Hi Mr. Dong,
The example doesn't work ...
******* must do some changes firts ... sorry !!!!
Carlos N. Porras
(El Salvador)