This is a migrated thread and some comments may be shown as answers.

Access parent item value in child binding

2 Answers 54 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Donna Stewart
Top achievements
Rank 1
Donna Stewart asked on 07 Jan 2014, 04:34 AM
I need the parent's item while binding the child item setting it's action.  I need to pass the categoryName from the category (parent) on the child action call.  Is this possible?  If so, how?  Any help is very much appreciated!

Here is the panelbar code:
@(Html.Kendo().PanelBar()
.Name("MainMenu")
.ExpandMode(PanelBarExpandMode.Single)
.BindTo(Model, mappings =>
    {
        mappings.For<GMCWeb.Areas.bi.Models.ReportCategory>(binding => binding
            .ItemDataBound((item, category) =>
                {
                    item.Text = "<div class='row'><div class='col-md-9'>" + category.categoryName + "</div><div class='col-md-3 menu-arrow'><i class='fa fa-arrow-circle-right fa-2x'></i></div></div>";
                    item.Encoded = false;
                })
                .Children(category => category.reportCategories));
        mappings.For<GMC.CustomerInformation.DashboardParameters.ReportCategoryInformation>(binding => binding
            .ItemDataBound(
            (item, reportCategory) =>
               {
               item.Text = reportCategory.ReportCategoryName;
               item.Enabled = !reportCategory.Disabled;
               item.Action("GetReports", "Home", new RouteValueDictionary { { "category", category.categoryName } });
               }));    
    }))

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 08 Jan 2014, 03:05 PM
Hello Donna,

The MenuItem has a reference to its parent through the Parent property. You can get the parent menu item like this:
.ItemDataBound((item, product) =>
{
    var parent = item.Parent;
                         
    item.Text = product.ProductName + " " + parent.Enabled.ToString();
}));

At this point the parent data item (in your case category) is no longer available. The only way to retrieve it is to find it manually.

Regards,
Georgi Krustev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Donna Stewart
Top achievements
Rank 1
answered on 08 Jan 2014, 03:33 PM
Thank you!
Tags
PanelBar
Asked by
Donna Stewart
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Donna Stewart
Top achievements
Rank 1
Share this question
or