It is early days, but this seems to be on the money. Will keep testing and report back. There are no spurious results and any selection that do not match returns no values. Which is good.
However, can I be cheeky and ask if you have any ideas on how I can limit the last dropdown by 2 values (BrandID and StyleID) rather than the 1 value it is receiving at the moment. Currently the last drop-down populates with all items that are a property
of StyleID and this means that there are too many selections to choose and if you choose a value that does not also link with the BrandID, we get null result. We need to populate the drop-down with the correct values we can remove another area of 'error'.
Yet again my hats of to you and thank you very much.
how I can limit the last dropdown by 2 values (BrandID and StyleID) rather than the 1 value
I'm not so acquainted in javascript, so look with prudence at my suggestion.
Try replacing
$('#styleID').change(function () {
var styleID = $(this).val();
$.getJSON('/GetDesigns/'+ styleID, function (getDesigns) {
with
$('#styleID').change(function () {
var styleID = $(this).val();
var brandID = $('#brandID').val();
$.getJSON('/GetDesigns/'+ styleID + '/' + brandID, function (getDesigns) {
and modify your GetDesigns.cshtml file adding a row like the following
var brandId = UrlData[1].IsEmpty() ? 1 : UrlData[1].AsInt();
to read the second UrlData and adding a second condition to your sql query
var sql = "SELECT DesignId, Designs FROM your_table WHERE BrandID = @0 AND StyleID = @1 ORDER BY Designs";
var product = db.Query(sql, brandId, styleId);
If it isn't obvious how to modify the GetDesigns.cshtml, post the code of your file.
Hi, thanks for looking into this for me. It works!! I know it is early days but after clearing the cache and putting the proper tables etc. It is popluated with the proper number of drop down items!!! wow, hats off and thank you. I have posted my code for
other people like me so they can see how we got this working. However, if anything goes wrong I will be back seeking further help. :-)
@{Layout=null;varbrandid=UrlData[1].IsEmpty()?1:UrlData[1].AsInt();varstyleid=UrlData[0].IsEmpty()?1:UrlData[0].AsInt();vardb=Database.Open("A-LensCatFE-01SQL");varsql="SELECT DesignID, Designs FROM dbo.qryFilteredDesigns WHERE BrandID = @0 AND StyleID = @1 ORDER BY DesignID";vargetDesigns=db.Query(sql,brandid,styleid);Json.Write(getDesigns,Response.Output);}
I am tentatively going to mark this as resolved. Thank you.
Liquidmetal
Member
24 Points
176 Posts
Re: How can you pass the results of many cascading dropdowns to "filter" another list?
Feb 27, 2013 08:55 AM|LINK
It is early days, but this seems to be on the money. Will keep testing and report back. There are no spurious results and any selection that do not match returns no values. Which is good.
However, can I be cheeky and ask if you have any ideas on how I can limit the last dropdown by 2 values (BrandID and StyleID) rather than the 1 value it is receiving at the moment. Currently the last drop-down populates with all items that are a property of StyleID and this means that there are too many selections to choose and if you choose a value that does not also link with the BrandID, we get null result. We need to populate the drop-down with the correct values we can remove another area of 'error'.
Yet again my hats of to you and thank you very much.
GmGregori
Contributor
5470 Points
737 Posts
Re: How can you pass the results of many cascading dropdowns to "filter" another list?
Feb 27, 2013 01:39 PM|LINK
I'm not so acquainted in javascript, so look with prudence at my suggestion.
Try replacing
$('#styleID').change(function () { var styleID = $(this).val(); $.getJSON('/GetDesigns/'+ styleID, function (getDesigns) {with
$('#styleID').change(function () { var styleID = $(this).val(); var brandID = $('#brandID').val(); $.getJSON('/GetDesigns/'+ styleID + '/' + brandID, function (getDesigns) {and modify your GetDesigns.cshtml file adding a row like the following
to read the second UrlData and adding a second condition to your sql query
var sql = "SELECT DesignId, Designs FROM your_table WHERE BrandID = @0 AND StyleID = @1 ORDER BY Designs"; var product = db.Query(sql, brandId, styleId);If it isn't obvious how to modify the GetDesigns.cshtml, post the code of your file.
Liquidmetal
Member
24 Points
176 Posts
Re: How can you pass the results of many cascading dropdowns to "filter" another list?
Feb 27, 2013 02:08 PM|LINK
Hi, thanks for looking into this for me. It works!! I know it is early days but after clearing the cache and putting the proper tables etc. It is popluated with the proper number of drop down items!!! wow, hats off and thank you. I have posted my code for other people like me so they can see how we got this working. However, if anything goes wrong I will be back seeking further help. :-)
getDesigns: