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

[Solved] Problem in Content of Panelbar Items.

2 Answers 180 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
devika godse
Top achievements
Rank 1
devika godse asked on 07 May 2010, 12:43 PM
I am using panelbar for employee details. I have a list containing Employee data.

Code:-
<% Html.Telerik().PanelBar()
            .Name("PanelBar")
            .HtmlAttributes(new { style = "width: 800px; float: left; margin-bottom: 30px;" })
            .ExpandMode(PanelBarExpandMode.Single)
            .SelectedIndex(0)
            .Items(items =>       
            {
                 foreach (Employee i in EmployeeList)
                 {
                     items.Add().Text(i.Name).Content(() =>
                     {  
                          %>
                              <div>
                                     <strong><%= i.EmpCode%></strong><br/>
                                     <%= i.Designtn%>
                                      
                           </div>
                          <%
                     });
                 }
            }).Render(); %>

Problem is-

Panelbar items shows all the employee names bt content of each item is Details i.e. EmpCode and Designtn of Last employee.

How do I solve this???

2 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 15 Oct 2010, 03:45 AM

I had the same problem as you.
The problem is that you're passing in a lambda expression as a parameter. The i variable is defined outside of the expression that's why you're seeing details of the last employee in each panel.

Try passing a string parameter instead, like so:

items.Add().Text(i.Name).Content(string.Format("<div><strong>{0}</strong></div><br/>{1}", Html.Encode(i.EmpCode), Html.Encode(i.Designtn)));

That solved the problem for me.
 

0
Darrien
Top achievements
Rank 1
answered on 04 Apr 2011, 03:41 AM
Chris - Awesome solution. Very simple and effective. Thanks!
Tags
PanelBar
Asked by
devika godse
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Darrien
Top achievements
Rank 1
Share this question
or