Skip to content

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

License

Notifications You must be signed in to change notification settings

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •