Skip to main content
A newer version of this page is available. .

How to: Add an Unbound Column to Supply Additional Data

Assume that ASPxCardView is bound to a data table that contains the “UnitPrice” and “Quantity” fields. There is no field that represents the total sum, as this can be calculated manually as follows: UnitPrice*Quantity. This example shows how to add an unbound column to the ASPxCardView control to represent the total sum of an order.

The image below shows the result.

ASPxCardview_Ex_CustomUnboundColumnData

    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;
        }
    }