protected void BtnCreateCategory_OnClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(DropDownListCreateParentCategory.SelectedValue))
            {
                categories newCategory = new categories()
                {
                    Name = TxtBoxNameCreateCategoryName.Text
                };
                if (CategoryDB.AddCategory(newCategory))
                {
                    LabelMessageCreateCategory.Style.Add(HtmlTextWriterStyle.Color, "green");
                    LabelMessageCreateCategory.Text = newCategory.Name + " was created!";
                }
                else
                {
                    LabelMessageCreateCategory.Style.Add(HtmlTextWriterStyle.Color, "red");
                    LabelMessageCreateCategory.Text = "Category could not be created!";
                }

            }
            else
            {
                subcategories newSubCategory = new subcategories()
                {
                    Name = TxtBoxNameCreateCategoryName.Text,
                    categories_Id =
                        (CategoryDB.GetCategoryById(int.Parse(DropDownListCreateParentCategory.SelectedValue)) != null
                            ? int.Parse(DropDownListCreateParentCategory.SelectedValue)
                            : 0)
                };

                if (SubCategoryDB.AddSubCategory(newSubCategory))
                {

                    LabelMessageCreateCategory.Style.Add(HtmlTextWriterStyle.Color, "green");
                    LabelMessageCreateCategory.Text = newSubCategory.Name + " was created under " +
                                                      CategoryDB.GetCategoryById(
                                                          int.Parse(DropDownListCreateParentCategory.SelectedValue))
                                                          .Name + "!";
                }
                else
                {
                    LabelMessageCreateCategory.Style.Add(HtmlTextWriterStyle.Color, "red");
                    LabelMessageCreateCategory.Text = "SubCategory could not be created!";
                }

            }

            //Refresh treeview.
            AddCategoryNodesToTreeView(TreeViewCategories);
        }
 private List<subcategories> FilterDropDownSubCatItems(categories cat)
 {
     PopulateDropDownSubCat(SubCategoryDB.GetAllSubCategoryByCategory(cat));
     return SubCategoryDB.GetAllSubCategoryByCategory(cat).ToList();
 }
 private void FindSubCategoriesAndAddToParentCategoryNode(categories category, TreeNode categoryNode)
 {
     foreach (var subC in SubCategoryDB.GetAllSubCategoryByCategory(category).OrderBy(subC => subC.Name).ToList()
         )
     {
         TreeNode subCategoryNode = new TreeNode
         {
             Text = subC.Name,
             Value = "subcategory_" + subC.Id,
             ShowCheckBox = true,
             SelectAction = TreeNodeSelectAction.Expand,
             ImageUrl = "~/Images/folder_25x25.png"
         };
         //Lägger det aktuella TermSet'et.
         categoryNode.ChildNodes.Add(subCategoryNode);
     }
 }
 //Redundant metod för att hitta alla ChildTerm och TermSets för att sedan ta bort dem.
 private void DeleteAllSubCategoriesForCategory(categories category)
 {
     foreach (var subCat in category.subcategories)
     {
         if (SubCategoryDB.DeleteSubCategoryById(subCat.Id) != 0)
             LabelDisplay.Text += "(SubCategory) " + subCat.Name + ",<br>";
     }
 }