Skip to main content

Unbound Columns

  • 3 minutes to read

The Bootstrap Grid View supports bound and unbound columns. Bound columns obtain their data from a control’s data source. Unbound columns are not bound to any field in a data source. These columns can be populated manually by handling the ASPxGridView.CustomUnboundColumnData event or by specifying an expression using the GridViewDataColumn.UnboundExpression used to evaluate values for this field. The Expressions section describes the syntax for creating expressions.

There is no difference between working with bound and unbound columns. You can sort, group, display summaries and filter unbound columns in the same manner as bound columns.

An unbound column meets the following requirements.

Providing Data for Unbound Columns

Data for unbound columns is generally obtained from a custom data source or is calculated based upon the values of bound columns.

To allow data editing for an unbound column, its data should be retrieved from a custom data source. When an end-user modifies column data within the Grid View, it should then be saved back to the data source.

To provide data for unbound columns and save the changes made by end-users, handle the ASPxGridView.CustomUnboundColumnData event. This event is raised only for unbound columns.

Example

Assume that the Bootstrap Grid View is bound to an “Orders” data table (NWind database), which contains the “UnitPrice”, “Quantity” and “Discount” fields. There is no field that represents the total sum, as this can be calculated manually as follows: UnitPrice*Quantity*(1-Discount). This example shows how to add an unbound column to the Grid View control to represent the total sum of an order.

using System;
using DevExpress.Web.Bootstrap;

protected void Page_Load(object sender, EventArgs e) {
    if (!IsCallback) {
        // Creates a column, customizes its settings and appends it to the Columns collection;
        BootstrapGridViewDataTextColumn colTotal = new BootstrapGridViewDataTextColumn();
        colTotal.Caption = "Total";
        colTotal.FieldName = "Total";
        colTotal.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
        colTotal.VisibleIndex = BootstrapGridView1.VisibleColumns.Count;
        colTotal.PropertiesTextEdit.DisplayFormatString = "c2";
        BootstrapGridView1.Columns.Add(colTotal);
    }
}

protected void Grid_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridViewColumnDataEventArgs e) {
    if (e.Column.FieldName == "Total") {
        decimal unitPrice = Convert.ToDecimal(e.GetListSourceFieldValue("UnitPrice"));
        int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));
        decimal discount = Convert.ToDecimal(e.GetListSourceFieldValue("Discount"));
        e.Value = unitPrice * quantity * (1 - discount);
    }
}

The image below shows the result.

BootstrapCustomUnboundColumnData