jeudi 20 août 2015

Adding CheckBoxes to Telerik RadMenu Child items

Hi I have a RadMenu that is dynamically populated. I need to add a checkbox to each of the child items on the menu, and then allow the user to make multiple selections. Once they make those selections a button will be clicked to sort a grid. Can this be done? Can you add a checkbox to the dynamic data? I'll post my code below.

<telerik:RadMenu ID="handsetMenu" runat="server">   
                    <Items>   

                    </Items>                                           
</telerik:RadMenu> 

  protected void createFilter(int categoryid)
{
    List<int> productIds = new List<int>();
    DataRow[] productRow = CategoriesProductsData.Tables["Products"].Select("Category_ID = " + 573);

    productIds = productRow.Select(p => int.Parse(p["Product_ID"].ToString())).ToList();

    ITCProductService pService = new TCProductServiceClient();
    var productTuples = (pService.GetProductsAttributes(productIds));

    List<Tuple<int, CustomAttribute>> customAttributes = new List<Tuple<int, CustomAttribute>>();
    foreach (var productTuple in productTuples)
    {
        foreach (var attributeTuple in productTuple.m_Item2)
        {
            var customAttribute = new Tuple<int, CustomAttribute>(productTuple.m_Item1, new CustomAttribute(attributeTuple));
            customAttributes.Add(customAttribute);
        }

    }

    List<CustomAttributeCategory> categories = new List<CustomAttributeCategory>();

    var categoryList = customAttributes.Select(a => a.Item2).Select(a => a.Attribute.Category).GroupBy(a => a.AttributeCategoryId);

    var CatProdList = new List<CustomAttributeCategory>();

    foreach (var category in categoryList)
    {
        var CatProd = new CustomAttributeCategory();

        var prodIDList = from product in customAttributes
                         where product.Item2.Attribute.CategoryId == category.Key
                         select Tuple.Create(product.Item1, product.Item2);

        CatProd.Category = customAttributes.Select(a => a.Item2.Attribute.Category).Where(a => a.AttributeCategoryId == category.Key).FirstOrDefault();
        CatProd.ProdAttributesTuple = new List<Tuple<int, CustomAttribute>>();
        CatProd.ProdAttributesTuple = prodIDList.ToList();

        CatProdList.Add(CatProd);
    }

    foreach (var cat in CatProdList)
    {
        var itemCategory = new RadMenuItem(cat.Category.Name);

        handsetMenu.Items.Add(itemCategory);            

        var option = cat.ProdAttributesTuple.GroupBy(a => a.Item2.Attribute.Value).ToList();
        foreach (var attr in option)
        {                  

            itemCategory.Items.Add(new RadMenuItem(attr.Key));   
        }
    }

}

protected void handsetMenu_ItemDataBound(object sender, RadMenuEventArgs e)
{
    DataRowView row = (DataRowView)e.Item.DataItem;
}


public class CustomAttributeCategory
{
    public AttributeCategoryModel Category { get; set; }
    public List<Tuple<int, CustomAttribute>> ProdAttributesTuple { get; set; }
}

public class CustomAttribute
{
    public AttributeModel Attribute { get; set; }

    public List<int> ProductIds { get; set; }

    public CustomAttribute(AttributeModel attribute)
    {
        Attribute = attribute;
        ProductIds = new List<int>();
    }
}




Aucun commentaire:

Enregistrer un commentaire