This is a migrated thread and some comments may be shown as answers.
Translating Client-side event example
2 Answers 26 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.
Greg
Top achievements
Rank 1
Greg asked on 09 Dec 2010, 09:58 PM
I'm attempting,and failing, to translate the MVC Grid client-side selection example from C# to VB.Net.

I keep getting an error when I run it "Bound columns require a field or property access expression.". The column definitions seems to be the issue but I'm at a loss to figure out why.

Here's the view source:

<%= Html.Telerik().Grid(Of IEnumerable(Of GridTest01.Customer))("Customers") _
                        .Name("Customers") _
                        .Columns(Sub(columns)
                                     columns.Bound(Function(c As GridTest01.Customer) c.CustomerID)
                                     columns.Bound(Function(c As GridTest01.Customer) c.CompanyName)
                                     columns.Bound(Function(c As GridTest01.Customer) c.ContactName)
                                     columns.Bound(Function(c As GridTest01.Customer) c.Country)
                                 End Sub) _
                        .DataBinding(Function(dataBinding) dataBinding.Ajax().[Select]("_SelectionClientSide_Customers", "Grid")) _
                        .Pageable() _
                        .Sortable() _
                        .Selectable() _
                        .ClientEvents(Function(events) events.OnRowSelect("onRowSelected")) _
                        .RowAction(Sub(row)
                                       Dim temp As GridTest01.Customer = row.DataItem.Cast(Of GridTest01.Customer)()
                                       'row.Selected = row.DataItem.Cast(Of GridTest.Customer).CustomerID.Equals(ViewData("id"))
                                       row.Selected = temp.CustomerID.Equals(ViewData("id"))
                                   End Sub
                        )
     
%>
<h3>Orders (<span id="customerID"><%= ViewData("id")%></span>)</h3>
<%= Html.Telerik().Grid(Of IEnumerable(Of GridTest01.Order))("Orders") _
                        .Name("Orders") _
                        .Columns(Sub(columns)
                                     columns.Bound(Function(c As GridTest01.Order) c.OrderID)
                                     columns.Bound(Function(c As GridTest01.Order) c.OrderDate).Format("{0:dd/MM/yyyy}")
                                     columns.Bound(Function(c As GridTest01.Order) c.ShipAddress)
                                     columns.Bound(Function(c As GridTest01.Order) c.ShipCity)
                                 End Sub) _
                        .DataBinding(Function(dataBinding) dataBinding.Ajax().[Select]("_SelectionClientSide_Orders", "Grid", New With { _
                                        Key .customerID = "ALFKI" _
                        })) _
                        .Pageable() _
                        .Sortable()
%>

Controller source:
Imports Telerik.Web.Mvc
 
<HandleError()> _
Public Class HomeController
    Inherits System.Web.Mvc.Controller
 
    Function Index() As ActionResult
        ViewData("Message") = "Welcome to ASP.NET MVC!"
 
        Return View()
    End Function
 
    Public Function SelectionClientSide(ByVal id As String) As ActionResult
        ViewData("Customers") = GetCustomers()
        ViewData("Orders") = GetOrdersForCustomer(If(id, "ALFKI"))
        ViewData("id") = "ALFKI"
        Return View()
    End Function
 
    <GridAction()> _
    Public Function _SelectionClientSide_Orders(ByVal customerID As String) As ActionResult
        customerID = If(customerID, "ALFKI")
        Return View(New GridModel(Of Order)() With { _
         .Data = GetOrdersForCustomer(customerID) _
        })
    End Function
 
    <GridAction()> _
    Public Function _SelectionClientSide_Customers() As ActionResult
        Return View(New GridModel(Of Customer)() With { _
         .Data = GetCustomers() _
        })
    End Function
 
    Private Shared Function GetOrdersForCustomer(ByVal customerId As String) As IEnumerable(Of Order)
        Dim northwind As New NorthwindDataContext()
 
        Return From order In northwind.Orders
               Where order.CustomerID = customerId
               Select order
    End Function
 
    Private Shared Function GetCustomers() As IQueryable(Of Customer)
        Dim northwind As New NorthwindDataContext()
        Return northwind.Customers
    End Function
 
    Function About() As ActionResult
        Return View()
    End Function
End Class

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 10 Dec 2010, 09:57 AM
Hello Greg,

Looking at the code you have pasted, it seems that the declaration of the grid is not correct. The grid generic parameter's type should be the type of the entity itself instead of collection of the entities.

<%= Html.Telerik().Grid(Of GridTest01.Customer)("Customers") _
                        .Name("Customers") _
'declaration...
%>


Regards,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Greg
Top achievements
Rank 1
answered on 10 Dec 2010, 02:07 PM
Ok, that got me on the right track. Thanks.

I'm guessing that I'm not the only one out there who is C# challenged or free. ;) Here's the updated line in case anyone else runs into the same issue.

<%= Html.Telerik().Grid(DirectCast(ViewData("Customers"), IEnumerable(Of Customer))) _
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Greg
Top achievements
Rank 1
Share this question
or