sum up values in Gridview based on condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parshupooja
    New Member
    • Jun 2007
    • 159

    sum up values in Gridview based on condition

    Hey All,

    I have stored procedure which return results like this:

    Sale person -----------qty-------Status
    Jack----------------------100-------1
    Jack----------------------200-------0
    Mike----------------------50-------0
    Mike----------------------55-------1


    There are only 2 records per sale person.I want to display these records in gridview as:
    Qty should be sum of qty irrespective to Status and pending should be sum of qty where Status is 1.
    For ex for above scenario it should look like this:

    Sale person -----------qty--------pending
    Jack----------------------300----------100
    Mike----------------------105------------55


    any Suggestion?
    Thanks!
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by parshupooja
    Hey All,

    I have stored procedure which return results like this:

    Sale person -----------qty-------Status
    Jack----------------------100-------1
    Jack----------------------200-------0
    Mike----------------------50-------0
    Mike----------------------55-------1


    There are only 2 records per sale person.I want to display these records in gridview as:
    Qty should be sum of qty irrespective to Status and pending should be sum of qty where Status is 1.
    For ex for above scenario it should look like this:

    Sale person -----------qty--------pending
    Jack----------------------300----------100
    Mike----------------------105------------55


    any Suggestion?
    Thanks!
    What have you tried so far to solve this problem?
    You should do your calculations when you are creating the Data Source for your GridView....or else modify your SQL so that it does these calculations... .

    -Frinny

    Comment

    • parshupooja
      New Member
      • Jun 2007
      • 159

      #3
      I have been suggested by our DBA not to anything on Sql Server beyond this , So this is farthest point I can go. I have surely to do something on page behind.

      I thought I would read each row in databound of Gridview and then do Calculation but I don't understand How to do that.
      Any suggestion?

      Originally posted by Frinavale
      What have you tried so far to solve this problem?
      You should do your calculations when you are creating the Data Source for your GridView....or else modify your SQL so that it does these calculations... .

      -Frinny

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by parshupooja
        I have been suggested by our DBA not to anything on Sql Server beyond this , So this is farthest point I can go. I have surely to do something on page behind.

        I thought I would read each row in databound of Gridview and then do Calculation but I don't understand How to do that.
        Any suggestion?
        What data type are you using as the GridView's data source?

        -Frinny

        Comment

        • parshupooja
          New Member
          • Jun 2007
          • 159

          #5
          GridView1.DataS ource = Sales.getSales( txtFrom.Text, txtTo.Text)
          GridView1.DataB ind()

          I have method getSales(0 in Sales class

          Originally posted by Frinavale
          What data type are you using as the GridView's data source?

          -Frinny
          Last edited by parshupooja; May 9 '08, 06:36 PM. Reason: sa

          Comment

          • ammoos
            New Member
            • Apr 2007
            • 100

            #6
            Assign this “Sales.getSales (txtFrom.Text, txtTo.Text)” function to a datatable.. and then you can get the data row by row.. then apply sum logic to calculate the data according to your conditions. Then assign the calculated data with the “sales person” to another datatable, which have the same column names of the first datatable.. Then assign the new datatable to the grid

            Comment

            Working...