This question is locked. New answers and comments are not allowed.
Brian Mains
Top achievements
Rank 1
Brian Mains
asked on 11 Nov 2009, 03:51 PM
Hello,
Can you use a foreach (..) in the content() method? I need to render multiple items with custom content... Basically, I want to render a list of items with a checkbox...
Can I do that in the PanelBar control?
Thanks.
Can you use a foreach (..) in the content() method? I need to render multiple items with custom content... Basically, I want to render a list of items with a checkbox...
Can I do that in the PanelBar control?
Thanks.
4 Answers, 1 is accepted
0
Accepted
Hi Brian,
Use this approach:
For further information review this online help topic.
Best wishes,
Georgi Krustev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Use this approach:
<% var list = new List<string> { "fisrt", "second", "last" }; Html.Telerik().PanelBar().Name("PanelBar1") .BindTo(list, (item, stringName) => { item.Text = stringName; item.Content = () => { %> <label for="chk"> <% Response.Write(stringName); %> </label> <input type="checkbox" name="chkBox" id="chk" /> <% }; }) .Render();%>For further information review this online help topic.
Best wishes,
Georgi Krustev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Steve
Top achievements
Rank 1
answered on 08 Dec 2009, 03:07 AM
This is exactly what I was looking for - thank you.
(Perhaps consider updating documentation for this!)
0
Jim
Top achievements
Rank 1
answered on 18 Jan 2010, 07:51 PM
This post was helpful for me, but I need to take it one layer further. I need to populate a single item of the PanelBar with subItems of names found in an xml document and associate those names with an action. The code I am testing with is as follows:
This works well for just a few membes, but as the member list grows, I need a way to extract the First and Last name as well as the id from the xml file and then build a subitem as shown in my example. The member list changes from time to time and I don't want to have to change the code to facilitate a member change.
Thanks for any help you can give.
Jim
| items.Add().Text("Members") |
| .Items(subItems => |
| { |
| subItems.Add().Text("John Doe").Action("GetMember", "Members", new { id = "300001" }); |
| }); |
This works well for just a few membes, but as the member list grows, I need a way to extract the First and Last name as well as the id from the xml file and then build a subitem as shown in my example. The member list changes from time to time and I don't want to have to change the code to facilitate a member change.
Thanks for any help you can give.
Jim
0
Brian Mains
Top achievements
Rank 1
answered on 18 Jan 2010, 07:58 PM
Hey,
Yeah, looping should work:
.Items((subitems) =>
{
XDocument doc = XDocument.Load(..);
foreach (XElement elem in doc.Root.Elements())
{
subitems.Add().Text(elem.Element("FirstName").Value + " " + elem.Element("LastName").Value). ...
}
}
Yeah, looping should work:
.Items((subitems) =>
{
XDocument doc = XDocument.Load(..);
foreach (XElement elem in doc.Root.Elements())
{
subitems.Add().Text(elem.Element("FirstName").Value + " " + elem.Element("LastName").Value). ...
}
}