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