0

私はシンプルDevexpress Gridviewです。

ここに画像の説明を入力

ここにコード;

<dx:ASPxGridView ID="grid" runat="server" DataSourceID="MasterDataSource" Width="100%"
        AutoGenerateColumns="False" KeyFieldName="CategoryID">
        <Columns>
            <dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0" />
            <dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1" />
            <dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2" />
        </Columns>
        <SettingsDetail ShowDetailRow="True" ExportMode="Expanded" />
        <Templates>
            <DetailRow>
                <dx:ASPxGridView ID="detailGrid" runat="server" AutoGenerateColumns="False" DataSourceID="DetailDataSource"
                    KeyFieldName="ProductID" Width="100%" OnBeforePerformDataSelect="detailGrid_BeforePerformDataSelect">
                    <SettingsDetail IsDetailGrid="true" ExportIndex="0" />
                    <Columns>
                        <dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1" />
                        <dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2" />
                        <dx:GridViewDataTextColumn FieldName="QuantityPerUnit" VisibleIndex="3" />
                    </Columns>
                </dx:ASPxGridView>

Unit PriceDevexpressで列の小計を計算する方法はありますか?

この例では; 一番下の列の合計Unit Price(18 + 19 + 4.5 + 14 + 18 + 263.5 + 18 + 46 + 14 + 14 + 15 = 430) が必要です。

どうやってやるの?

よろしくお願いします、

ソナー

4

2 に答える 2

1

これは、次の方法で ASPxGridView を使用して実装できます。

1) 別の方法で集計を計算します。2) 詳細 GridView の DataBound および BeforeGetCallBackResult イベント ハンドラーを使用して、ラベルのテキストを設定します。これが私のコードです:

protected int CalcPageSummary(ASPxGridView gridView, string fieldName) {
    GridViewDataColumn column = gridView.Columns[fieldName] as GridViewDataColumn;
    if(column == null)
        return 0;
    int pageIndex = gridView.PageIndex;
    int startRowIndex = pageIndex * gridView.SettingsPager.PageSize;
    int finishRowIndex = startRowIndex + gridView.SettingsPager.PageSize;
    if(finishRowIndex > gridView.VisibleRowCount)
        finishRowIndex = gridView.VisibleRowCount;
    int result = 0;
    for(int i = startRowIndex; i < finishRowIndex; i++) 
        result += Convert.ToInt32(gridView.GetRowValues(i, fieldName));
    return result;
}

private void SetColumnSummary(ASPxGridView gridView, string fieldName) {
    ASPxLabel lbl = gridView.FindFooterCellTemplateControl(gridView.Columns[fieldName], "ASPxLabel1") as ASPxLabel;
    if(lbl != null)
        lbl.Text = CalcPageSummary(gridView, fieldName).ToString();
}
protected void ASPxGridView2_BeforeGetCallbackResult(object sender, EventArgs e) {
    SetColumnSummary((ASPxGridView)sender, "UnitPrice");
}
protected void ASPxGridView2_BeforePerformDataSelect(object sender, EventArgs e) {
    Session["CategoryID"] = (sender as ASPxGridView).GetMasterRowKeyValue();
}
protected void ASPxGridView2_DataBound(object sender, EventArgs e) {
    SetColumnSummary((ASPxGridView)sender, "UnitPrice");
}
于 2011-03-21T19:27:43.997 に答える
0

devexpress についてはわかりませんが、通常のグリッドビューでは、合計を簡単に計算してフッターに表示できます。

 double GrdTotal = 0;
    protected void grdList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        double price = Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "UnitPrice"));
        GrdTotal += price;
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblTotalPrice = (Label)e.Row.FindControl("UnitPrice");
            lblTotalPrice.Text = GrdTotal.ToString();
        }
    }
于 2011-03-20T19:53:30.543 に答える