I have this code which, on the front-end, will create dependent selectboxes (subcategories are dependent on the category) using LINQ:
foreach (var cat in (from category in KB.Categories
orderby category.name
select category)) {
this.categories.Add(cat.id, cat.name);
}
foreach (var sub_cat in (from subcategory in KB.SubCategories
orderby subcategory.name
select subcategory)) {
this.subcategories.Add(sub_cat.id, sub_cat.name);
if (!this.subcategoryCategory.containsKey) {
this.subcategoryCategory.Add(sub_cat.category_id, new ArrayList());
}
// I'd like to put the sub_cat_id at the end of the arraylist
// for the category_id, but this line doesn't seem to work
//this.subcategoryCategory[sub_cat.category_id] = sub_cat.id;
}
How can I do this?
Perhaps there a way to build a giant JSON object instead of the three variables (categories, subCategoryCategory, subcategories)?
Is there a better/different way to do this that I've completely missed?
P.S. Coming from a different programming paradigm, I'm not doing this in the standard ASP.NET (webforms or MVC) way, but I am using codebehind to generate the values.