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 or Total of a column in DataGrid changes when I click on Edit Row - Need help

Sum or Total of a column in DataGrid changes when I click on Edit Row - Need help

Scheduled Pinned Locked Moved ASP.NET
csshelptutorialquestion
2 Posts 1 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.
  • S Offline
    S Offline
    Slow Learner
    wrote on last edited by
    #1

    Hi, I am summing a column in my DataGrid and displaying total at the footer with the below piece of code If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then 'Snip out the ViewCount Dim ContributionWithHeld As Integer = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ContributionWithHeld")) myTotalContributionWithHeld += ContributionWithHeld ElseIf e.Item.ItemType = ListItemType.Footer Then e.Item.Cells(20).Text = "Total: " & String.Format("{0:#,###}", myTotalContributionWithHeld) End If and it works great and it dispaly the correct total when it binds the data. But if I click on Edit row button in the grid then the Sum/Total at the footer changes (deducts the value of that cell in that row from the total). Looks like the the row that is in Edit mode is not being taken into acount while summing the values. Can some one help me with this how to change the above code or what I else I need to do to display the Sum correct even if any of the rows in Edit mode. Also, the other thing I would like to be able to do is when a row in Edit mode and as I change the value in the Cell that I would like Sum , the Sum at the footer needs to be changed. May be I need to do it under OnCellChange event but not sure where and how do I do it as I never done this before. Please help. Thanks, -L

    S 1 Reply Last reply
    0
    • S Slow Learner

      Hi, I am summing a column in my DataGrid and displaying total at the footer with the below piece of code If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then 'Snip out the ViewCount Dim ContributionWithHeld As Integer = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ContributionWithHeld")) myTotalContributionWithHeld += ContributionWithHeld ElseIf e.Item.ItemType = ListItemType.Footer Then e.Item.Cells(20).Text = "Total: " & String.Format("{0:#,###}", myTotalContributionWithHeld) End If and it works great and it dispaly the correct total when it binds the data. But if I click on Edit row button in the grid then the Sum/Total at the footer changes (deducts the value of that cell in that row from the total). Looks like the the row that is in Edit mode is not being taken into acount while summing the values. Can some one help me with this how to change the above code or what I else I need to do to display the Sum correct even if any of the rows in Edit mode. Also, the other thing I would like to be able to do is when a row in Edit mode and as I change the value in the Cell that I would like Sum , the Sum at the footer needs to be changed. May be I need to do it under OnCellChange event but not sure where and how do I do it as I never done this before. Please help. Thanks, -L

      S Offline
      S Offline
      Slow Learner
      wrote on last edited by
      #2

      HI, Looks like it also works good as expected when I changed the If statement to include 'Or e.Item.ItemType = ListItemType.EditItem' at the end. So I am good with the Sum/Total now. But when I change the Cell I would like the Total/Sum also be changed. Any help appreciated. Thanks, -L

      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