I made a code to show the records using 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:
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. In that user only decide which column they want to display. If they select Price column_name in select statement. 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. e.g. for footer summary
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