We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid - Row Calculations Custom

Hello. I am coming from using the Obout.com grid control which I used to calculate some values. Is it possible to do the same thing using the ASP.net Grid by Syncfusion? If so, is there any sample or help to direct me? Thank you very much!

Here is an example of the results shown:

And here is the code to produce those results:
public void RowDataBound(object sender, GridRowEventArgs e)
    {
        try
        {
            //Individual Rows
            if (e.Row.RowType == GridRowType.DataRow)
            {
                //This will remove sales tax for a reseller.
                if (((GridDataControlFieldCell)e.Row.Cells[8]).Text == "True")
                {
                    salesTaxRate = 0;
                }
                else
                {
                    salesTaxRate = Convert.ToDecimal(s.SalesTaxRate);;
                }
                //Column: WinningPrice / Price itemWinningPrice
                decimal itemPrice = decimal.Parse(e.Row.Cells[9].Text);

                //Calculate amounts
                decimal itemTax = salesTaxRate * itemPrice;
                decimal itemBuyerPremium = buyerPremiumRate * itemPrice;
                decimal itemTotal = itemPrice + itemTax + itemBuyerPremium;
                decimal itemCashPrice = (buyerPremiumRate - cashDiscount) * itemPrice + itemTax + itemPrice;
                //////

                //Display Values

                //Tax
                e.Row.Cells[10].Text = itemTax.ToString("C");
                //Buyer Premium
                e.Row.Cells[11].Text = itemBuyerPremium.ToString("C");
                //Item Total
                e.Row.Cells[12].Text = itemTotal.ToString("C");
                //Cash Price
                e.Row.Cells[13].Text = itemCashPrice.ToString("C");

                //Add item price to total
                totalItemPriceForUser += itemPrice;
            }
            else if (e.Row.RowType == GridRowType.GroupFooter)
            {
                //Show Total for User:
                decimal totalTaxForUser = 0;
                decimal totalBuyerPremiumForUser = 0;
                decimal totalLineTotalForUser = 0;
                decimal totalCashPriceForUser = 0;
                //Tax
                totalTaxForUser = totalItemPriceForUser * salesTaxRate;
                //Rounding
                totalTaxForUser = Math.Round(totalTaxForUser, 2, MidpointRounding.AwayFromZero);

                //Buyer Premium
                totalBuyerPremiumForUser = totalItemPriceForUser * buyerPremiumRate;
                //Rounding
                totalBuyerPremiumForUser = Math.Round(totalBuyerPremiumForUser, 2, MidpointRounding.AwayFromZero);

                //Total
                totalLineTotalForUser = totalItemPriceForUser + totalTaxForUser + totalBuyerPremiumForUser;
                //Rounding
                totalLineTotalForUser = Math.Round(totalLineTotalForUser, 2, MidpointRounding.AwayFromZero);

                //Cash Price
                totalCashPriceForUser = totalItemPriceForUser + totalTaxForUser + totalItemPriceForUser * (buyerPremiumRate - cashDiscount);
                //Rounding
                totalCashPriceForUser = Math.Round(totalCashPriceForUser, 2, MidpointRounding.AwayFromZero);

                //Display Totals
                e.Row.Cells[2].Text = "<strong><span style =\"text-decoration: underline;\"> Total for User:</span></strong>";
                //Total Item Price
                e.Row.Cells[9].Text = "<strong>" + totalItemPriceForUser.ToString("C") + "</strong>";
                e.Row.Cells[10].Text = "<strong>" + totalTaxForUser.ToString("C") + "</strong>";
                e.Row.Cells[11].Text = "<strong>" + totalBuyerPremiumForUser.ToString("C") + "</strong>";
                e.Row.Cells[12].Text = "<strong>" + totalLineTotalForUser.ToString("C") + "</strong>";
                e.Row.Cells[13].Text = "<strong>" + totalCashPriceForUser.ToString("C") + "</strong>";



                //Add to grand totals

                //Item Price
                grandTotalItemPrice += totalItemPriceForUser;
                //Tax
                grandTax += totalTaxForUser;
                //Buyer Premium
                grandBuyerPremium += totalBuyerPremiumForUser;
                //Line Total
                grandLineTotal += totalLineTotalForUser;
                //Cash Price
                grandcashPrice += totalCashPriceForUser;

                //Reset the values to 0
                totalItemPriceForUser = 0;
                totalTaxForUser = 0;
                totalBuyerPremiumForUser = 0;
                totalCashPriceForUser = 0;
                totalLineTotalForUser = 0;
            }
            else if (e.Row.RowType == GridRowType.ColumnFooter)
            {
                //Display Grand Totals
                e.Row.Cells[2].Text = "<strong>Grand Total for All:</strong>";
                e.Row.Cells[9].Text = "<strong>" + grandTotalItemPrice.ToString("C") + "</strong>";
                e.Row.Cells[10].Text = "<strong>" + grandTax.ToString("C") + "</strong>";
                e.Row.Cells[11].Text = "<strong>" + grandBuyerPremium.ToString("C") + "</strong>";
                e.Row.Cells[13].Text = "<strong>" + grandcashPrice.ToString("C") + "</strong>";
                e.Row.Cells[12].Text = "<strong>" + grandLineTotal.ToString("C") + "</strong>";
            }


            if (e.Row.RowType == GridRowType.DataRow)
            {
                //Group Header
                if (lastGroupHeader != null)
                {
                    Literal textContainer = lastGroupHeader.Cells[0].Controls[0].Controls[lastGroupHeader.Cells[0].Controls[0].Controls.Count - 1].Controls[0] as Literal;
                    textContainer.Text = "<u>Username: <strong>" + ((GridDataControlFieldCell)e.Row.Cells[7]).Text;
                    textContainer.Text += "</strong> Full Name: " + ((GridDataControlFieldCell)e.Row.Cells[3]).Text;
                    textContainer.Text += " " + ((GridDataControlFieldCell)e.Row.Cells[4]).Text;
                    textContainer.Text += " Phone Number: " + ((GridDataControlFieldCell)e.Row.Cells[5]).Text;
                    textContainer.Text += " City: " + ((GridDataControlFieldCell)e.Row.Cells[6]).Text;
                    textContainer.Text += " State: " + ((GridDataControlFieldCell)e.Row.Cells[14]).Text + "</u>";

                    lastGroupHeader = null;
                }

            }
            else if (e.Row.RowType == GridRowType.GroupHeader)
            {
                //Sets something :) 
                if (e.Row.GroupLevel == 0)
                {
                    lastGroupHeader = e.Row;

                }
            }
        }
        catch
        {

        }
    }


3 Replies

JK Jayaprakash Kamaraj Syncfusion Team February 10, 2017 12:58 PM UTC

Hi Warren, 

Thank you for contacting Syncfusion support. 

In Grid, Summary feature used to aggregate a particular column. If you want to show total summary also in Grid we need to set ShowTotalSummary as True in SummaryRow . Please refer to the below help document and online demo sample. 





Note: Also the APIs used in ASP.NET and MVC wrapper is similar to that JavaScript APIs. For example, in JavaScript showSummary is used to enable filtering to grid whereas in ASP.NET and MVC, the first letter is capitalized in the property ie ShowSummary. 
 
Please refer the below link for more information on the various API’s available for rendering the grid control.  
 

Regards, 

Jayaprakash K. 



WC Warren Churulich February 10, 2017 01:03 PM UTC

Thank you!


JK Jayaprakash Kamaraj Syncfusion Team February 13, 2017 03:52 AM UTC

Hi Warren, 
 
Thanks for the update. 
 
Please get back to us if you need any further assistance.   
 
Regards, 
 
Jayaprakash K. 


Loader.
Up arrow icon