This is a migrated thread and some comments may be shown as answers.
How to dynamically add Items to a panelbar
0 Answers 47 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy McShane
Top achievements
Rank 1
Andy McShane asked on 02 May 2012, 12:59 PM
Hi, I am trying to figure out to add items and sub-items dynamically to a tabstrip at runtime and simply cannot figure out how to do it. Here is what I have so far
@{     Html.Telerik().PanelBar()
           .Name("PanelBar")
           .ExpandMode(PanelBarExpandMode.Single)
           .HtmlAttributes(new { style = "width: 100%;" })
           .Items(panelbar =>
                      {
                          panelbar.Add().Text("Milestones")
                              .SpriteCssClasses("milestone")
                              .Items(parent => parent.Add().Text("Manage")
                                                           .SpriteCssClasses("smlOption")
                                                           .HtmlAttributes(new {data_url = Url.Action("Index", "Milestone")})).Expanded(false);
                               panelbar.Add().Text("Workflow Stages")
                                             .SpriteCssClasses("stages")
                                             .Items(parent => {parent.Add().Text("Grid")
                                                                            .SpriteCssClasses("icon-ajax-grid");
                                                               parent.Add().Text("Editor")
                                                                            .SpriteCssClasses("icon-ajax-editor");
                                             }).Expanded(false);
                               panelbar.Add().Text("Enumerations")
                                             .SpriteCssClasses("movie")
                                             .Items(parent =>
                                             {
                                                 parent.Add().Text("Grid")
                                                              .SpriteCssClasses("icon-ajax-grid");
                                                 parent.Add().Text("Editor")
                                                              .SpriteCssClasses("icon-ajax-editor");
                                             }).Expanded(false);
                               panelbar.Add().Text("Url")
                                             .SpriteCssClasses("urlIcon")
                                             .Items(parent =>
                                             {
                                                 parent.Add().Text("Grid")
                                                              .SpriteCssClasses("icon-ajax-grid");
                                                 parent.Add().Text("Editor")
                                                              .SpriteCssClasses("icon-ajax-editor");
                                             }).Expanded(false);                             
           })
           .ClientEvents(events => events.OnSelect("Select")) 
           .Render();
}

This works great as it is but wjhat I need to do is to be able to add items dynamically based upon the model, such as using a foreach loop, something like this maybe?
@{     Html.Telerik().PanelBar()
           .Name("PanelBar")
           .ExpandMode(PanelBarExpandMode.Single)
           .HtmlAttributes(new { style = "width: 100%;" })
           .Items(panelbar =>
                      {
                          panelbar.Add().Text("Milestones")
                              .SpriteCssClasses("milestone")
                              .Items(parent => parent.Add().Text("Manage")
                                                           .SpriteCssClasses("smlOption")
                                                           .HtmlAttributes(new {data_url = Url.Action("Index", "Milestone")})).Expanded(false)
                                                           .Items(
                                                            
                                                           @foreach (var i in Model)
                                                            {
                                                                parent => parent.Add().Text(i.TreatmentShortName)
                                                            }
                                                            
                                                           )

Which obviously does not work. Can this be done?
Tags
PanelBar
Asked by
Andy McShane
Top achievements
Rank 1
Share this question
or