We have a ASPxGridView control that has (among others) two columns "A" and "B". They are decimal numbers such as A=8.869 and B=3.372.
We wish to include another column "A-B" that is the calculation of A-B. So in this case 8.869 - 3.372=5.479. So A-B would be 5.479.
We'd like to calculate this for each the rows in the GridView. How to do that?
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" KeyFieldName="device_id">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<ClearFilterButton Visible="True">
</ClearFilterButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="device_id" ReadOnly="True"
VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="device_meter_id" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="device_A" VisibleIndex="6" Caption="A">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="device_B" VisibleIndex="7" Caption="B">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn VisibleIndex="8" Caption="A-B">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowFilterRow="True" ShowGroupPanel="True" />
</dx:ASPxGridView>
Excellent! Works great. Took a bit of testing to see what to put in the GetListSourceFieldValue. It is the name of the column in the sql table, as you know (but I didn't).
For others, if necessary, here's the code that worked:
protected void grid_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e)
{
if (e.Column.FieldName == "myFieldInGridView")
{
decimal a = Convert.ToDecimal(e.GetListSourceFieldValue("sql_database_column_5"));
decimal b = Convert.ToDecimal(e.GetListSourceFieldValue("sql_database_column_6"));
e.Value = a - b;
}
}
and this in the gridview control:
OnCustomUnboundColumnData="grid_CustomUnboundColumnData"
Hello John,
Thank you for informing us that the problem has been resolved. I have approved the Answer of Isaac Khazi user.
You can mark the answer as a Solution and close the question:
http://www.devexpress.com/Support/Center/FAQ