ASPxGridView.CustomUnboundColumnData Event
Enables data to be supplied to unbound columns.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v18.2.dll
Declaration
Event Data
The CustomUnboundColumnData event's data class is ASPxGridViewColumnDataEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Column | Gets the unbound column currently being processed. |
IsGetData | Gets whether you should provide data for the currently processed cell. Inherited from ASPxGridColumnDataEventArgs. |
IsSetData | Gets whether the cell’s value should be stored in a custom data source. Inherited from ASPxGridColumnDataEventArgs. |
ListSourceRowIndex | Gets the current data item’s (row, card or record) index in the data source. Inherited from ASPxGridColumnDataEventArgs. |
Value | Gets or sets the value of the cell currently being processed. Inherited from ASPxGridColumnDataEventArgs. |
The event data class exposes the following methods:
Method | Description |
---|---|
GetListSourceFieldValue(Int32, String) | Returns the value of the specified field in the specified data item (row, card or record) in the control’s underlying data source. Inherited from ASPxGridColumnDataEventArgs. |
GetListSourceFieldValue(String) | Returns the value of the specified cell in the processed data item (row, card or record) in the control’s underlying data source. Inherited from ASPxGridColumnDataEventArgs. |
Remarks
The CustomUnboundColumnData event is fired for unbound columns only. To create an unbound column, add a new data column to the ASPxGridView.Columns collection and set its GridViewDataColumn.UnboundType property to an appropriate value, based on the type of data the column is supposed to display. This column’s GridViewDataColumn.FieldName property value must be unique and it must not refer to any field in the ASPxGridView’s underlying data source.
When the ASPxGridView is loaded, it raises the CustomUnboundColumnData event for each cell in unbound columns, allowing you to populate cells with data. By default, the event’s ASPxGridColumnDataEventArgs.IsGetData parameter is set to true. In this instance, you need to supply data for the currently processed cell. Obtain the required value from a custom data source and assign it to the ASPxGridColumnDataEventArgs.Value parameter.
The event’s ASPxGridColumnDataEventArgs.IsSetData parameter isn’t in effect. To save the modified data back to the data source, handle the ASPxGridView.RowUpdating event.
The currently processed cell is identified by the column and row, which can be determined via the ASPxGridViewColumnDataEventArgs.Column and ASPxGridColumnDataEventArgs.ListSourceRowIndex properties, respectively.
The CustomUnboundColumnData event argument provides the ASPxGridColumnDataEventArgs.GetListSourceFieldValue method, allowing you to get the value of the required cell.
Example
using DevExpress.Web.ASPxGridView;
protected void Grid_Init(object sender, EventArgs e) {
// Creates a column, customizes its settings and appends it to the Columns collection;
GridViewDataTextColumn colTotal = new GridViewDataTextColumn();
colTotal.FieldName = "Total";
colTotal.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
colTotal.VisibleIndex = Grid.VisibleColumns.Count;
colTotal.PropertiesTextEdit.DisplayFormatString = "c2";
Grid.Columns.Add(colTotal);
}
// Populates the unbound column.
protected void Grid_CustomUnboundColumnData(object sender,
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);
}
}
<dx:ASPxGridView ID="Grid" ClientInstanceName="Grid" runat="server" AutoGenerateColumns="false"
DataSourceID="ProductsDataSource" KeyFieldName="OrderID" OnInit="Grid_Init" OnCustomUnboundColumnData="Grid_CustomUnboundColumnData">
<SettingsPager PageSize="5" />
<Columns>
<dx:GridViewDataTextColumn FieldName="ProductName" />
<dx:GridViewDataSpinEditColumn FieldName="UnitPrice" >
<PropertiesSpinEdit DisplayFormatString="c" DecimalPlaces="2" />
</dx:GridViewDataSpinEditColumn>
<dx:GridViewDataSpinEditColumn FieldName="Quantity" >
</dx:GridViewDataSpinEditColumn>
<dx:GridViewDataSpinEditColumn FieldName="Discount" >
<PropertiesSpinEdit DisplayFormatString="p0"></PropertiesSpinEdit>
</dx:GridViewDataSpinEditColumn>
</Columns>
</dx:ASPxGridView>
<ef:EntityDataSource runat="server" ID="ProductsDataSource" ContextTypeName="DevExpress.Web.Demos.NorthwindContext" EntitySetName="Invoices" />