/mvc-gridview-bind-to-in-memory-data-sources

Bind MVC GridView Extension columns to in-memory data sources (DataTable and List).

Primary LanguageVisual Basic .NETOtherNOASSERTION

Grid View for MVC - How to Bind a Grid to Standard In-Memory Data Sources (DataTable, List)

This example shows how to bind MVC GridView Extension columns to the following data sources:

Also, this example demonstrates how to create an unbound column and populate it with data.

A grid displays data from a DataTable

Use the GridViewSettings.Columns property to access the collection of grid columns.

Add four columns and bind them to the "ID", "Text", "Quantity", "Price" data source fields:

settings.Columns.Add("ID");
settings.Columns.Add("Text");
settings.Columns.Add("Quantity");
settings.Columns.Add("Price");

Then, add an unbound column whose values are calculated based on the values of bound columns. Use the unbound column's FieldName and UnboundType properties to specify the column name and value type. Calculate column values in the CustomUnboundColumnData event handler:

settings.Columns.Add(unboundColumn => {
    unboundColumn.FieldName = "UniqueFieldName";
    unboundColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
});
settings.CustomUnboundColumnData = (sender, e) => {
    if (e.Column.FieldName == "UniqueFieldName") {
        int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));
        decimal price = (decimal)e.GetListSourceFieldValue("Price");
        e.Value = quantity * price;
    }
};

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)