locked
Get Total Price from all selected/filtered records. RRS feed

  • Question

  • User-1305858305 posted

    Hello

    My GridView has PageSize = Enabled

    My SqlDataSource has "onSelecting" event and also Parameters and ControlParameters Enabled. 

    User filtering database and GridView displaying paged results. 

    I want to display some spesific values from this filtered results. 

    "We have 100 items and Total Price is 100.000USD - Filtered 90 items 90000USD - displaying only 50 records and 50.000USD"

    I can display total records via DataView, also displaying paged records too.

    But how can get filtered total records and price I dont know.

    How can I get this filtered results and display it?

    Thanks in advance.

    Wednesday, April 15, 2015 2:05 PM

Answers

  • User61956409 posted

    Hi omerdemir,

    Thanks for your post.

    "We have 100 items and Total Price is 100.000USD - Filtered 90 items 90000USD - displaying only 50 records and 50.000USD"

    You could refer to the following SQL statement to calculate total price for each page.

    select count(1)*1000 from YourTable where Id in (select top @pagesize Id from YourTable where Id not in (select top ((@currentpage-1)* @pagesize) Id from YourTable))

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 15, 2015 10:24 PM
  • User-1305858305 posted

    Hello and thank you for your reply,

    It was my mistake.

    This codes worked fine. 

     DataView dvSelectedStones = (DataView)sqlDataSourceGridView.Select(DataSourceSelectArguments.Empty);
            if (dvSelectedStones.Table.Rows.Count > 0)
            {
                LabelCountFilteredStonesCount.Text = "Selected :<span style='font-weight: bold;'> " + dvSelectedStones.Table.Rows.Count + "</span> Certificated Diamonds ";
            }
            else
            {
                LabelCountFilteredStonesCount.Text = "";
            }
           
            decimal SelectedTotalCarat = (decimal)dvSelectedStones.Table.Compute("SUM(Carat)", "");
           
            if (SelectedTotalCarat >  0)
            {
                LabelFilteredStonesTotalCarat.Text = SelectedTotalCarat.ToString();
            }
            else
            {
                LabelFilteredStonesTotalCarat.Text = "";
            }

    Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 16, 2015 2:56 AM

All replies

  • User61956409 posted

    Hi omerdemir,

    Thanks for your post.

    "We have 100 items and Total Price is 100.000USD - Filtered 90 items 90000USD - displaying only 50 records and 50.000USD"

    You could refer to the following SQL statement to calculate total price for each page.

    select count(1)*1000 from YourTable where Id in (select top @pagesize Id from YourTable where Id not in (select top ((@currentpage-1)* @pagesize) Id from YourTable))

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 15, 2015 10:24 PM
  • User-1305858305 posted

    Hello and thank you for your reply,

    It was my mistake.

    This codes worked fine. 

     DataView dvSelectedStones = (DataView)sqlDataSourceGridView.Select(DataSourceSelectArguments.Empty);
            if (dvSelectedStones.Table.Rows.Count > 0)
            {
                LabelCountFilteredStonesCount.Text = "Selected :<span style='font-weight: bold;'> " + dvSelectedStones.Table.Rows.Count + "</span> Certificated Diamonds ";
            }
            else
            {
                LabelCountFilteredStonesCount.Text = "";
            }
           
            decimal SelectedTotalCarat = (decimal)dvSelectedStones.Table.Compute("SUM(Carat)", "");
           
            if (SelectedTotalCarat >  0)
            {
                LabelFilteredStonesTotalCarat.Text = SelectedTotalCarat.ToString();
            }
            else
            {
                LabelFilteredStonesTotalCarat.Text = "";
            }

    Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 16, 2015 2:56 AM