Back to Devexpress

How to: Add an Unbound Column to Supply Additional Data

aspnet-114327-components-card-view-examples-how-to-add-an-unbound-column-to-supply-additional-data.md

latest1.4 KB
Original Source

How to: Add an Unbound Column to Supply Additional Data

  • Dec 17, 2020

Assume that ASPxCardView is bound to a data table that contains the “UnitPrice” and “Quantity” fields. Since there is no field in the data source that represents the total sum, you can calculate it manually as follows: UnitPrice*Quantity. The following example adds an unbound column to the ASPxCardView control that displays each order’s total sum.

The image below shows the result.

csharp
protected void CardView_Init(object sender, EventArgs e) {
        CardViewTextColumn colTotal = new CardViewTextColumn();
        colTotal.Caption = "Total";
        colTotal.FieldName = "Total";
        colTotal.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
        colTotal.VisibleIndex = CardView.Columns.Count;
        colTotal.PropertiesTextEdit.DisplayFormatString = "c2";
        CardView.Columns.Add(colTotal);
    }
    protected void CardView_CustomUnboundColumnData(object sender, ASPxCardViewColumnDataEventArgs e) {
        if (e.Column.FieldName == "Total") {
            decimal unitPrice = Convert.ToDecimal(e.GetListSourceFieldValue("UnitPrice"));
            int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));
            e.Value = unitPrice * quantity;
        }
    }