Example E2836
Visible to All Users

Grid View for ASP.NET MVC - How to bind grid to XPO in server mode

This example demonstrates how to use the GridViewExtension.BindToLINQ method to bind the GridView extension to a LINQ to XPO data source.

C#
@Html.DevExpress().GridView(settings => { settings.Name = "gvDataBindingToLinq"; // ... }).BindToLINQ(string.Empty, string.Empty, (s, e) => { e.KeyExpression = "Oid"; DevExpress.Xpo.Session session = XpoHelper.GetNewSession(); DevExpress.Xpo.XPQuery<MyObject> query = new DevExpress.Xpo.XPQuery<MyObject>(session); e.QueryableSource = query; }).GetHtml()

Files to Review

Documentation

Example Code

E2836/Views/Home/_GridViewPartial.cshtml
Razor
@using E2836.Models @using E2836.Helpers @Html.DevExpress().GridView(settings => { settings.Name = "gvDataBindingToLinq"; settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" }; settings.KeyFieldName = "Oid"; settings.Width = Unit.Percentage(100); settings.Settings.ShowFilterRow = true; settings.Settings.ShowGroupPanel = true; settings.Settings.ShowFooter = true; settings.Columns.Add("Title", MVCxGridViewColumnType.TextBox).Width = Unit.Percentage(70); }).BindToLINQ(string.Empty, string.Empty, (s, e) => { e.KeyExpression = "Oid"; DevExpress.Xpo.Session session = XpoHelper.GetNewSession(); DevExpress.Xpo.XPQuery<MyObject> query = new DevExpress.Xpo.XPQuery<MyObject>(session); e.QueryableSource = query; }).GetHtml()
E2836/Views/Home/_GridViewPartial.vbhtml
Code
@Imports E2836 @Html.DevExpress().GridView(Sub(settings) settings.Name = "gvDataBindingToLinq" settings.CallbackRouteValues = New With { Key .Controller = "Home", Key .Action = "GridViewPartial" } settings.KeyFieldName = "Oid" settings.Width = Unit.Percentage(100) settings.Settings.ShowFilterRow = True settings.Settings.ShowGroupPanel = True settings.Settings.ShowFooter = True settings.Columns.Add("Title", MVCxGridViewColumnType.TextBox).Width = Unit.Percentage(70) End Sub).BindToLINQ(String.Empty, String.Empty, Sub(s, e) e.KeyExpression = "Oid" Dim session As DevExpress.Xpo.Session = XpoHelper.GetNewSession() Dim query As New DevExpress.Xpo.XPQuery(Of MyObject)(session) e.QueryableSource = query End Sub).GetHtml()

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.