Page 1 of 1
Need dropdown listbox using categoryID, parentID, level
Posted: Thu Apr 17, 2008 10:53 am
by lab_n_chemicals
Can anyone modify categorydropdownlist to include categoryID, parentID, level as query parameters so I can set up my major categories as separate lists?
Thx in advance
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Fri Apr 18, 2008 4:52 am
by m_plugables
You need to modify the
ConLib/CategoryDropDownList.ascx.cs file. Locate the following line of code in the file
Code: Select all
subcatList.Add(new ListItem(prefix + subcat.Name, subcat.CategoryId.ToString()));
and replace with the following line of code
Code: Select all
subcatList.Add(new ListItem(prefix + subcat.Name, subcat.CategoryId.ToString()+","+subcat.ParentId.ToString()+","+level.ToString()));
Now made the
CategoryRedir() function look like
Code: Select all
private void CategoryRedir()
{
string[] queryParameters = CategoryList.SelectedValue.Split(',');
int categoryId = AlwaysConvert.ToInt(queryParameters[0]);
int parentId = AlwaysConvert.ToInt(queryParameters[1]);
int level = AlwaysConvert.ToInt(queryParameters[2]);
if (categoryId == 0) Response.Redirect(NavigationHelper.GetHomeUrl());
Category category = CategoryDataSource.Load(categoryId);
if (category != null)
{
Response.Redirect(category.NavigateUrl);
}
}
Now CategoryId, ParenId and Level all information is available in the above function for usage.
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Fri Apr 18, 2008 2:18 pm
by lab_n_chemicals
Thx very much. Appreciate you time.
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Wed Jul 15, 2009 5:10 pm
by deadlybuda
Hi, could I get some further clarification on this code?
In my situation, I have 3 major cateogories: Brands, Lighting, and Collections. I need a separate drop down list for each category.
How would I use this code to specify, for example, just "Collections"? I assume I have to plug in the CategoryID somewhere, but I can't figure out where to do it.
Any help would be greatly appreciated.
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Thu Jul 16, 2009 2:25 am
by mazhar
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Thu Jul 16, 2009 5:31 am
by Khaliq
deadlybuda wrote:Hi, could I get some further clarification on this code?
In my situation, I have 3 major cateogories: Brands, Lighting, and Collections. I need a separate drop down list for each category.
How would I use this code to specify, for example, just "Collections"? I assume I have to plug in the CategoryID somewhere, but I can't figure out where to do it.
Any help would be greatly appreciated.
Yes you can use the category Id in the control to get items only from that category. You can probably define a parameter CategoryId for the control and the place where you use it in the scriptlet you can set the category id.
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Mon May 10, 2010 7:27 pm
by mmackrell
This is a great post, but I have a question. I assume that I would set the parent category id in the scriplet. This is what I have in the scriptlet and it appears to not be working:
[[ConLib:Custom/SimpleCategoryList ]]
[[ConLib:Custom/CategoryDropDownList Levels="1" Prefix="." AutPostBack="true" CacheDuration="0" parentId="5373"]]
I have also tried changing the category id in the aspx like you referenced in
viewtopic.php?f=44&t=11652 and that does not work either.
I am not a developer, so direction would be appreciated.
Oh, I would also like to know where I would go to set the width for this dropdown list. I put have played around with putting this in it's own div with a set width, but that doesn;t seem to be cutting it. Is there a setting in the aspx.cs file that would control the wrap of the list?
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Mon May 10, 2010 8:08 pm
by mmackrell
I figured out where to set the width for the drop down list - yay...
Again, any help with setting the parent category id would be greatly appreciated.
Regards,
Margie
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Tue May 11, 2010 6:13 am
by mazhar
mmackrell wrote:I figured out where to set the width for the drop down list - yay...
Again, any help with setting the parent category id would be greatly appreciated.
Regards,
Margie
This control doesn't support any ParentId parameter at scriptlet level. The discussion being done in few posts above makes use of custom parent id parameter passed through query string. If you want to support ParentId in this control to list child categories only that can be used via scriptlet then you need to put something like in this control.
Code: Select all
private int _ParentId;
public int ParentId
{
get{return _ParentId;}
set{_ParentId=value;}
}
finally locate following code
Code: Select all
categoryList = GetCategoryListItemsRecursive(0, startLevel);
and change it like
Code: Select all
categoryList = GetCategoryListItemsRecursive(ParentId, startLevel);
Now save it and give a try via passing parent id through scriptlet.
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Wed May 12, 2010 5:10 pm
by mmackrell
This works GREAT!!! Thanks for all your help Mazhar
Margie
Re: Need dropdown listbox using categoryID, parentID, level
Posted: Sat Sep 04, 2010 3:40 pm
by mmackrell
Mazhar,
Another quick question pertaining to this. I only want one level appearing from my parent category, so I enter
Code: Select all
[[ConLib:Custom/CategoryDropDownList Levels="1" AutPostBack="true" HomeText=" Hospitals by Department" CacheDuration="0" Prefix="" ParentId="5525"]]
However, I am still seeing more the one level down, how do I correct this? I have tried setting the levels to 0 and I still see multiple levels down.
Thanks in advance.
Margie