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

[Solved] Grid initial Load - custom columns

1 Answer 27 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.
orim
Top achievements
Rank 1
orim asked on 09 Aug 2012, 07:46 AM
Hi,
i am coding in VB:NET. I need to load a Grid from SERVERBINDING. No strongly type view.

View (code)
<%: Html.Telerik.Grid(Of TestModels.RequestQueue)("GridRequests").Name("GridRequests")%>

Controller (code this works)
 Function RequestsByLogin() As ActionResult
 
            'Initial load for Telerik Grid
            ViewData("GridRequests") = a4gContext.RequestQueue.ToList
                                        
 
            Return PartialView()
 
        End Function


Controller (code does not work, Grid shows no Data, want to request only 4 columns)
Function RequestsByLogin() As ActionResult 'Initial load for Telerik Grid ViewData("GridRequests") =  (From req In a4gContext.RequestQueue                     Where req.CreatedUser = User.Identity.Name                     Select req.RequestGuid, req.Status, req.CTI, req.CreatedDate).ToList Return PartialView() End Function

Whats the problem ?

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 13 Aug 2012, 04:38 PM
Hello,

You should to create a strongly typed ViewModel in the projection with the needed properties instead  
of an anonymous type and specify the type to the Grid in this scenario e.g.

Html.Telerik.Grid(Of TestModels.RequestQueueViewModel)("GridRequests").Name("GridRequests")
ViewData("GridRequests") = (From req In a4gContext.RequestQueue
                  Where req.CreatedUser = User.Identity.Name
                  Select New RequestQueueViewModel With {.RequestGuid = req.RequestGuid, .Status = req.Status,.CTI = req.CTI,.CreatedDate = req.CreatedDate).ToList
The alternative is not to use projection and specify the Grid columns so that only the four properties are displayed.

Kind regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Grid
Asked by
orim
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or