Hi,
I implemented the code that you provided. Still no success. Below is the code that I'm trying to execute:
1) CustomContentCategories Class:
using System;
using System.Collections;
using Telerik.Cms.Engine;
using Telerik.Cms.Engine.WebControls.Admin;
using Telerik.Security;
using Telerik.Web.UI;
namespace PersonalFN.WebControls.Admin
{
public delegate void CategoriesEventHandler(object sender, EventArgs e);
public class CustomContentCategoriesField : ContentCategoriesField
{
public event CategoriesEventHandler ItemSelected;
public override string LayoutTemplatePath
{
get
{
object obj = this.ViewState["LayoutTemplatePath"];
if (obj != null)
return (string)obj;
return "~/Sitefinity/Admin/ControlTemplates/Generic_Content/CategoriesField.ascx";
}
set
{
this.ViewState["LayoutTemplatePath"] = value;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls();
}
protected override void InitializeControls(System.Web.UI.Control controlContainer)
{
if (content == null && ContentId != Guid.Empty)
content = this.Manager.GetContent(ContentId);
if (content != null)
{
object objSelectedCategory = content.GetMetaData("Category");
selectedCategory = objSelectedCategory != null ? objSelectedCategory.ToString() : String.Empty;
}
this.CategoriesList.SelectedIndexChanged += CategoriesList_SelectedIndexChanged;
this.CategoriesList.MarkFirstMatch = true;
this.CategoriesList.AllowCustomText = false;
IList categories = this.Manager.GetCategories(0, 0, "CategoryName");
RadComboBoxItem liUncategorized = new RadComboBoxItem();
liUncategorized.Text = "* Uncategorized *";
liUncategorized.Value = string.Empty;
if (String.IsNullOrEmpty(selectedCategory))
liUncategorized.Selected = true;
this.CategoriesList.Items.Add(liUncategorized);
AddCategory(Guid.Empty, categories);
}
private void AddCategory(Guid parentId, IList categories)
{
foreach (ICategory category in categories)
{
if (this.CategoriesList.FindItemByValue(category.ID.ToString()) == null && category.ParentCategoryID == parentId)
{
RadComboBoxItem categoryItem = new RadComboBoxItem(category.CategoryName, category.CategoryName);
int level = CalculateLevel(category, categories);
if (level > 0)
categoryItem.Style.Add("padding-left", string.Concat((10 * level), "px"));
if (category.CategoryName == selectedCategory)
categoryItem.Selected = true;
this.CategoriesList.Items.Add(categoryItem);
AddCategory(category.ID, categories);
}
}
}
private static int CalculateLevel(ICategory category, IList categories)
{
int level = 0;
while (category.ParentCategoryID != Guid.Empty)
{
level++;
foreach (ICategory category1 in categories)
{
if (category.ParentCategoryID == category1.ID)
{
category = category1;
break;
}
}
}
return level;
}
private void CategoriesList_SelectedIndexChanged(object sender, EventArgs e)
{
RadComboBox list = (RadComboBox)sender;
if (list.SelectedItem.Value != String.Empty)
selectedCategory = list.SelectedItem.Value;
if (ItemSelected != null)
ItemSelected(sender, e);
}
private IContent content;
private string selectedCategory;
}
}
2) The NewsItemNew usercontrol (~/Sitefinity/Admin/ControlTemplates/News/NewsItemNew.ascx) :
3) ControlsConfig.xml file (~/App_Data/Configuration/Telerik.Sitefinity.Configuration.ControlsConfig.xml)
In spite of this, whenever I select any item from the Category dropdown (please refer the screenshot), the SelectedIndexChanged event does not get fired.
Am I missing something ?
Thanks,
Saumitra