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

[Solved] Child items displayed in column.

4 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Troy Demet
Top achievements
Rank 2
Troy Demet asked on 26 Oct 2011, 05:31 PM
I am attempting to display a grid and in one column the child items for the Model are displayed.
@Html.Telerik.Grid(Model).Name("ServicesGridView").Datakeys( _
      Function(datakey) datakey.Add(Function(c) c.ServiceGroupId) _
          ).DataBinding(Function(dataBinding) _
                            dataBinding.Server.Update("ServicesGroupsEdit","Settings")).Columns( _
      Function(columns) {columns.Bound(Function(c) c.ServiceGroupId).Hidden(True), _
                         columns.Bound(Function(c) c.ServiceGroupName), _
                         columns.Bound(Function(c) c.ServiceGroupDescription).Title("Group Description"), _
                         columns.Template(Function(c) c.ServiceInfoList.ForEach(Function(l) l.Name & "[" & l.ServiceMenuId & "]")), _
                         columns.Command( _
                             Function(commands) commands.Edit().ButtonType(GridButtonType.Image))})


The ForEach loop gives me an error of "Expression does not produce a value." Any help with this would be greatly appreciated.

4 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 27 Oct 2011, 09:01 AM
Hello Troy Demet,

I have attached a sample project showing how to create a template column in VB.NET and Razor. Here is the relevant part:

@ModelType IEnumerable(Of TelerikMvcApplication52.Product)
 
@Code
Html.Telerik().Grid(Model).Name("Grid") _
   .Columns(Sub (columns)
      columns.Bound(Function (p) p.ID)
      columns.Template(Function(p)
          @<text>
            <strong>@p.ID</strong>
          </text>                    
      End Function)
   End Sub)  _
   .Render()
End Code

Kind regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Troy Demet
Top achievements
Rank 2
answered on 27 Oct 2011, 07:31 PM
I tried the code you sent and go odd results.
The sub items were listed above the grid.
Here is the code I used.
@Html.Telerik.Grid(Model).Name("ServicesGridView").DataKeys( _
      Function(datakey) datakey.Add(Function(c) c.ServiceGroupId) _
          ).DataBinding(Function(dataBinding) _
                            dataBinding.Server.Update("ServicesGroupsEdit", "Settings") _
                            ).Columns(Sub(columns)
                                              columns.Bound(Function(c) c.ServiceGroupId).Hidden(True)
                                              columns.Bound(Function(c) c.ServiceGroupName).HtmlAttributes(New With {.style = "vertical-align:top;background-color:<#= Color #>;"})
                                              columns.Bound(Function(c) c.ServiceGroupDescription).Title("Group Description").HtmlAttributes(New With {.style = "vertical-align:top;"})
                                              columns.Template(Function(c)
                                                                       For Each item In c.ServiceInfoList
                                                                           @<text>
                                                                               <div><strong>@item.Name</strong> [@item.ServiceMenuId]</div>
                                                                           </text>                                                                           
                                                                       Next
                                                               End Function)
                                              columns.Template(Function(c) Html.ActionLink("Edit", "ServicesGroupsEdit", "Settings", New With {.id = c.ServiceGroupId}, New With {.class = "t-button"}).ToString).HtmlAttributes(New With {.style = "vertical-align:top;"})
                                      End Sub)

0
Atanas Korchev
Telerik team
answered on 28 Oct 2011, 07:45 AM
Hello Troy Demet,

 This is because you must define the grid in a @code block and use its render method. Please check again the test project. The grid is defined like this:

@Code
Html.Telerik().Grid(Model).Name("Grid") _
   .Columns(Sub (columns)
      columns.Bound(Function (p) p.ID)
      columns.Template(Function(p)
          @<text>
            <strong>@p.ID</strong>
          </text>                    
      End Function)
   End Sub)  _
   .Render()
End Code

All the best,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Troy Demet
Top achievements
Rank 2
answered on 28 Oct 2011, 02:24 PM
That did it. Thank you for your help.
-Troy
Tags
Grid
Asked by
Troy Demet
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Troy Demet
Top achievements
Rank 2
Share this question
or