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. GridView control data calculation?

GridView control data calculation?

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripthelpquestion
2 Posts 2 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
    Sasmi
    wrote on last edited by
    #1

    Dear Friends, I have created an GridView in which i want to calculate amount using javascript the scenario is like this. Row 1) Control * Control = Control 1 Row 2) -"- Row 3) -"- Row 4) -"- Row nth) Control * Control = Control nth Footer Row Total = Control 1 + control nth Output: Row 1) 1000 * 1 = 1000 Row 2) 10 * 1 = 10 Row 3) 100 * 1 = 100 Row 4) 1000 * 1 = 1000 Row nth) 1000 * 1 = 1000 Footer Row Total = 3110 the row created at runtime so that i cant used it properly can any one help me i am create this on ASP 2.0 using C# language Help me thaks in advance Sasmi

    H 1 Reply Last reply
    0
    • S Sasmi

      Dear Friends, I have created an GridView in which i want to calculate amount using javascript the scenario is like this. Row 1) Control * Control = Control 1 Row 2) -"- Row 3) -"- Row 4) -"- Row nth) Control * Control = Control nth Footer Row Total = Control 1 + control nth Output: Row 1) 1000 * 1 = 1000 Row 2) 10 * 1 = 10 Row 3) 100 * 1 = 100 Row 4) 1000 * 1 = 1000 Row nth) 1000 * 1 = 1000 Footer Row Total = 3110 the row created at runtime so that i cant used it properly can any one help me i am create this on ASP 2.0 using C# language Help me thaks in advance Sasmi

      H Offline
      H Offline
      Herman T Instance
      wrote on last edited by
      #2

      Hi, the gridview has an OnRowDataBound event. In that event you can do your thing like:

      Int32 Total = 0;
      Int32 ValueCol1 = 0;
      Int32 ValueCol2 = 0;
      Int32 Together = 0;
      if (e.Row.RowType.Equals(DataControlRowType.DataRow))
                  {
      
                      try
                      {
                          DataTable tabel = (DataTable)myGridView.DataSource;
                          ValueCol1 = Convert.ToInt32(tabel.Rows[e.Row.RowIndex].ItemArray[0]);
                          ValueCol2 = Convert.ToInt32(tabel.Rows[e.Row.RowIndex].ItemArray[1]);
                          Together = ValueCol1 * ValueCol2;
                          Total += Together;
                      }
                      catch (Exception err)
                      {
                          lblError.Text = err.Message;
                      }
                  }
      if (e.Row.RowType.Equals(DataControlRowType.Footer))
      {
             e.Row.Cells[2].Text = Total.ToString();
      }
      

      for: ValueCol1 = Convert.ToInt32(tabel.Rows[e.Row.RowIndex].ItemArray[0]); find the appropriate field in the ItemArray. Field[0] is the first displayed field

      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