Search: | |||||

| ||||

Home » Forum » Asp.net | RSS Feeds |

I'm trying to calculate the total price of all the articles in a dataGrid of a caddy and write it down in the footer...

The problem is that i have to do that dynamical and that my page is rebind all the time (add new row, dropdownlists...)

I've tried it this way but this just don't work... (found example on DataGridGirl...)

Some facts:

* I don't get any message by my debugger, so i guess there are no syntax-faults

* I don't see the string: "Totale prijs" into the footer

* Showfooter is set on true...

Somebody knows how to handle this?

CODE SNIPPET:

Public Sub eventItemDataBound1(ByVal S As Object, ByVal e As DataGridItemEventArgs)

Dim drop1 As DropDownList = e.Item.FindControl("myDDL")

Dim indexInDataGrid As Integer = e.Item.ItemIndex

If Not IsNothing(drop1) Then 'zeer belangrijk => drop1 moet eerste bestaan!!!

...

' I Add dropdown here to the DataGrid...

...

'Bereken de Totale Som

Dim myTable As DataTable = myDataSet.Tables("OrderTabel")

Dim myDataRow As DataRow

Dim som As Double = 0

If (e.Item.ItemType = ListItemType.Footer) Then

For Each myDataRow In myTable.Rows

som = som + myTable.Rows(indexInDataGrid)("totaleprijs")

Next

e.Item.Cells(1).Text = "Totale prijs:"

e.Item.Cells(7).Text = som

End If

End If

End Sub

Take a look at Scott Mitchell's An Extensive Exam of the DataGrid Web Control, Part 13 at aspnet.4guysfromrolla.com/articles/020503-1.aspx

Your code is totaly unoptimized. You get data for each item, and header and footer. You should put everything inside if statement and don't forget to cast types. when calculating price and displaying it in Text property of TableCell. It's strange that you don't get any casting errors.

Your variable indexInDataGrid is of the same value when calculating sum. You don't actually calculate on each row of the DataTable. "foreach" statement should be excanged with "for" statement with counter to calculate the sum.

for (int i = 0; i<myTable.ROws.Count; i++)

sum += (Double)myTable.Row[i]["totaleprijs"];

Didn't find what you were looking for?
Find more on Calculate Total Sum
Or get search suggestion and latest updates.

Related Topics:

- Sum colunm total in repeater
- write a program that enters double data into an ArrayList and calculate the total
- sum of amount deliverd group
- custom Sum function?
- SUM content of rows
- count the sum of a column
- Loop, sum values and paste
- VBA code to sum
- Summing a range of variable size
- getting the sum of the last 20 cells
- Summing on varying number of rows in Excel using VBA
- sum in columns
- Summing a range
- Conditional Summing
- sum formula
- how to sum the even numbers only
- Sum values entered into text boxes
- Data Sum rows not hidded
- sum cells with conditional formatting color
- sum of series of natural numbers
- sum and difference of 2 bcd numbers
- Compute the sum of both positive and negative elements of an array
- Getting the sum and percentage in Excel coulmn
- sum and Multiply number and print in decimal
- Excel 2000: Time totaling variable 'overflows' at 24:00 and display