[英]How to perform footer summary and Group Summary in AspxGridView using dynamic binding?
I made a code to show the records using AspxGridView. 我编写了代码以使用AspxGridView显示记录。 Now I want to show the sum(Column_Name), count(Column_Name) for Footer and Grouping.
现在,我想显示页脚和分组的总和(列名),计数(列名)。
This is my code: 这是我的代码:
<dx:ASPxGridView ID="ASPxGridView1" runat="server" >
<SettingsPager PageSize="50">
</SettingsPager>
<Settings ShowFilterRow="True" ShowGroupPanel="True" ShowFooter="True" ShowGroupFooter="VisibleIfExpanded" />
<SettingsCommandButton>
<ShowAdaptiveDetailButton ButtonType="Image"></ShowAdaptiveDetailButton>
<HideAdaptiveDetailButton ButtonType="Image"></HideAdaptiveDetailButton>
</SettingsCommandButton>
<SettingsDataSecurity AllowDelete="False" AllowEdit="False" AllowInsert="False" />
<SettingsSearchPanel Visible="True" />
</dx:ASPxGridView>
C# code: C#代码:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
ASPxGridView1.Visible = true;
string cs = ConfigurationManager.ConnectionStrings["HQMatajerConnectionString"].ConnectionString;
whereQuery = getWhereQuery();
using (SqlConnection con = new SqlConnection(cs))
{
string querysss = "select "+txtSelectedColumn.Text+ @"
FROM [HQMatajer].[dbo].[Transaction] as transactions
RIGHT JOIN [HQMatajer].[dbo].[TransactionEntry] as transactionsEntry
ON transactions.TransactionNumber=transactionsEntry.TransactionNumber
INNER JOIN [HQMatajer].[dbo].[Item] as items
ON transactionsEntry.ItemID=items.ID
INNER JOIN [HQMatajer].[dbo].[Supplier] as suppliers
ON items.SupplierID=suppliers.ID
LEFT JOIN [HQMatajer].[dbo].[Department] as departments
ON departments.ID=items.DepartmentID
LEFT JOIN [HQMatajer].[dbo].[Category] as categories
ON categories.ID=items.CategoryID
where " + txtQuery.Text;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = querysss;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
ASPxGridView1.AutoGenerateColumns = true;
ASPxGridView1.DataSource = ds;
ASPxGridView1.DataBind();
}
}
You can notice that my sql query statement. 您可以注意到我的sql查询语句。 In that user only decide which column they want to display.
在该用户中,仅决定他们要显示的列。 If they select Price column_name in select statement.
如果他们在select语句中选择Price column_name。 It has to display sum(price) in footer for over all records and for grouping as well if user do grouping
如果要进行分组,则必须在页脚中显示总和(价格)以用于所有记录和分组
You could add a summary item in c# code and change the field name in every postback. 您可以在c#代码中添加摘要项,并在每次回发中更改字段名称。 eg for footer summary
例如页脚摘要
ASPxSummaryItem gs = new ASPxSummaryItem();
gs.FieldName = txtSelectedColumn.Text;
gs.SummaryType = DevExpress.Data.SummaryItemType.Sum;
this.ASPxGridView1.TotalSummary.Add(gs);
If the field name doesn't change, you can delete old summaries and add a new one every time at the desired column. 如果字段名称没有更改,则可以删除旧的摘要,并每次在所需的列中添加一个新的摘要。 You could also do the same for every group summary.
您还可以对每个组摘要执行相同的操作。 You could also check these out https://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridView_GroupSummarytopic and https://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridView_TotalSummarytopic
您也可以在https://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridView_GroupSummarytopic和https://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridView_TotalSummarytopic中查看这些内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.