DNNCommunity / DNNCommunity/DNN.Faq
Abilibty to Hide "All Categories" and Select the First Category
- Dominant language
- C#
- Stars
- 17
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
I made the following change in order to be able to hide the "All categories" that is usually initially selected if using the treeview option. It can get enabled by adding ShowCats="false" to the dnn:DnnTreeView node in the ASCX file. I have not tested the change for any other display type than TreeView. Once ShowCats is set to false, it will, in view mode, hide the "All categories" option and instead select the first category. In page edit mode, it will still display it.
Maybe someone wants to add it to the repo. (Am too lazy atm).
In FAQs.ascx.cs Page_Load I added this to the bottom of the IsPostBack if statement:
`
if (!IsPostBack)
{
...Other stuff...
if (!IsEditable)
{
if (treeCategories.Attributes["ShowAllCats"] != null)
{
if (treeCategories.Attributes["ShowAllCats"].Equals("false",
StringComparison.OrdinalIgnoreCase))
{
// Unselect "All Categories", select first cat node and hide "All Categories"
treeCategories.Nodes[0].Selected = false;
treeCategories.Nodes[1].Selected = true;
treeCategories.Nodes[0].Visible = false;
// Bind it again
BindData();
}
}
}
}
`
Initially I tried to simply comment out adding "All categories" in the BindCategories() method, but that did lead to some problems as the module expects that initially all questions are shown at least once to render the corresponding javascript correctly. If removing "All categories" at that point, only the questions of the first category would work, so I opted for this quick and dirty way.
Maybe someone else, would like the same change. I hope it helps.
Andy
Contributor guide
Research direction
Start in FAQs.ascx.cs, reviewing Page_Load, BindCategories(), and BindData(), along with the dnn:DnnTreeView declaration in the ASCX file. Verify the proposed attribute name and behavior for TreeView before implementing it. Done means view mode can hide “All Categories” and select the first category, while page edit mode still displays it and all questions render correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100