Hi, i'm having abit of trouble with some logic. I have the following functions:
Then i can bind to the GetCategoriesListBySectionId via the object datasource (to my dropdownlist) passing in the sectionid from the query string. This works fine however i don't like the idea of having two functions to do this. There was two reasons i did it this way.
1. I could need see how to pass constants via the objectdatasource select parameters.
2. I could not see how to recursively add the additional items to the list collection, therefore i passed it along with the function.
Appreciate if someone could tell me if this is possible. Thanks
Code:
public static ListItemCollection GetCategoriesListBySectionId(int sectionId) {
return GetCategoriesListItemBySectionId(null, sectionId, 0, "");
}
public static ListItemCollection GetCategoriesListItemBySectionId(ListItemCollection list, int sectionId, int parentId, string prefix) {
foreach (CategoriesItem category in Categories.GetCategoriesBySectionId(sectionId, parentId)) {
ListItem item = new ListItem();
item.Text = prefix + category.CategoryName;
item.Value = category.CategoryId.ToString();
list.Add(item);
Categories.GetCategoriesListBySectionId(list, sectionId, category.CategoryId, prefix + "##");
}
return list;
}
Then i can bind to the GetCategoriesListBySectionId via the object datasource (to my dropdownlist) passing in the sectionid from the query string. This works fine however i don't like the idea of having two functions to do this. There was two reasons i did it this way.
1. I could need see how to pass constants via the objectdatasource select parameters.
2. I could not see how to recursively add the additional items to the list collection, therefore i passed it along with the function.
Appreciate if someone could tell me if this is possible. Thanks