Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Sum 1

Status
Not open for further replies.

Ecreations

Programmer
Jul 6, 2002
220
CA
Hey Guys,
I have a form like this

Texstbox for Quantity Dropdownlist for skus and label for prices and an update button

I want to have the user input the quantity, pick the sku then click the update button and I want to show the total, state and federal taxes in another label.
all data is stored in sql database.

since asp.net doesnt have control arrays, whats the best way of doing such thing?

Any hints or help would be appreciated.

Thanks

 
You can write an SP that sums your total, then return the value to the label.

 
Thanks for the response dvannoy,
I know I can use an SP to return the sum to the label.
What I am trying to figure out is how to perform the addition for all the values of the fields.
to be more clear, if I have 10 labels with integer values, how can I add the integer values to each others and have the total in a different label?

 
if you wish to do it on th front end, you can do something like this.

Dim Price1 as Decimal
Dim Price2 as Decimal
Dim Total as Decimal

Price1 = CType(Label1.Text, Decimal)
Price2 = CType(Label2.Text, Decimal)
Total = CType(LabelTotal.Text,Decimal)

Total = ((Price1 + Price2))

LabelTotal.Text = Total.ToString
LabelTotal.Text = FormatCurrency(LabelTotal.Text, 2)

This should work for you

 
dvannoy,
Eventually I ended up doing it in a similar way.
I had no way of knowing how many textboxes will be there since they will be decided by the end user. so this is what I ended up with in case anyone needs to know.

Protected Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim dblTotal As Double = 0
Dim txtControl As New Control
Dim dblGrandTotal As Double
For Each txtControl In Me.form1.Controls
Dim tempTxt As TextBox
If TypeOf txtControl Is TextBox Then
tempTxt = CType(txtControl, TextBox)
If Not tempTxt.Text.Length = 0 Then
dblTotal = CType(tempTxt.Text, Double)
dblGrandTotal += dblTotal
End If
End If
Next
lblTotal.Text = dblGrandTotal.ToString("C")
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top