Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive function logic problems.

Status
Not open for further replies.

jgd123456

Programmer
Nov 3, 2006
19
GB
Hi, i'm having abit of trouble with some logic. I have the following functions:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top