Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Sum all values in datalist control

Sum all values in datalist control

Scheduled Pinned Locked Moved ASP.NET
salestutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Otekpo Emmanuel
    wrote on last edited by
    #1

    Good day friends! I taught this would be possible but I spend over 2hrs trying to figure this out but to no avail. This is what I want; I have datalist control that displays payment details and everything is working fine except one. Which is I want to display sum of all the payments made on a label control called Aggregate. For example Customer Name Amount Date Paul $2000 20-09-2016 Catherine $5000 20-09-2016 Otes $3000 20-09-2016 Aggregate = Sum of all payments made Any solution please... Thanks in advance...

    Z V 2 Replies Last reply
    0
    • O Otekpo Emmanuel

      Good day friends! I taught this would be possible but I spend over 2hrs trying to figure this out but to no avail. This is what I want; I have datalist control that displays payment details and everything is working fine except one. Which is I want to display sum of all the payments made on a label control called Aggregate. For example Customer Name Amount Date Paul $2000 20-09-2016 Catherine $5000 20-09-2016 Otes $3000 20-09-2016 Aggregate = Sum of all payments made Any solution please... Thanks in advance...

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      This sounds very easy to do. Where are you stuck?

      There are only 10 types of people in the world, those who understand binary and those who don't.

      O 1 Reply Last reply
      0
      • Z ZurdoDev

        This sounds very easy to do. Where are you stuck?

        There are only 10 types of people in the world, those who understand binary and those who don't.

        O Offline
        O Offline
        Otekpo Emmanuel
        wrote on last edited by
        #3

        Thanks for your reply. Am stuck at the summing. Help please

        Z 1 Reply Last reply
        0
        • O Otekpo Emmanuel

          Thanks for your reply. Am stuck at the summing. Help please

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #4

          Otekpo Emmanuel wrote:

          Help please

          I would love to but I have no idea what your problem is. It's like you went to the mechanic and said, "I can't drive my car." Do you think they could help?

          There are only 10 types of people in the world, those who understand binary and those who don't.

          1 Reply Last reply
          0
          • O Otekpo Emmanuel

            Good day friends! I taught this would be possible but I spend over 2hrs trying to figure this out but to no avail. This is what I want; I have datalist control that displays payment details and everything is working fine except one. Which is I want to display sum of all the payments made on a label control called Aggregate. For example Customer Name Amount Date Paul $2000 20-09-2016 Catherine $5000 20-09-2016 Otes $3000 20-09-2016 Aggregate = Sum of all payments made Any solution please... Thanks in advance...

            V Offline
            V Offline
            Vincent Maverick Durano
            wrote on last edited by
            #5

            Handle ItemDataBound event to do the calculation. Here's a quick example for your reference:

            int total = 0;
            protected void DataList1_ItemDataBound(Object sender, DataListItemEventArgs e)
            {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
            //access the Amount values here
            //for example, if you are displaying it in a Label control
            Label lbAmount = (Label) e.Item.FindControl("YourLabelControlID");
            total += Convert.ToInt32(lbAmount.Text);
            }
            else if (e.Item.ItemType == ListItemType.Footer){
            //Find the total label in the Footer
            Label lblTotal = (Label)e.Item.FindControl("YourLabelControlID");
            lblTotal.Text = total.ToString();
            }
            }

            Note: If your Amount value contains a dollar symbol, then you may need to trim that value first before doing a Convert.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups