• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need some visual basic .net help

Ladies Man

Platinum Member
ok.... since my teacher is all wise and mighty he decided to combine 2 exercises and the book doesn't explain how to do both things that I need to do.


I have a Datagrid with information in it, along with some labels above it that have information.
Information comes from 1 access database, and is made up of 2 tables

I can get the information to come up in all the labels and in the datagrid..... so i know the binding is right...
When i go first, next, previous, last... all the right info comes up


Ok... Now i need to add up 4 different things from within the datagrid.
Like how many are listed.... what is the total of the things that are listed...

ex.

ID TotalPay
1 10
2 20
3 30

So i would need a label to show 3 listings, total pay = 60


I can get it to add it up correctly for the first record that comes up, but if you click to the next record, it still thinks the information should be from the first record, so the information doesn't change.

I've tried putting in refreshes, clears, my brain is done.

Hopefully what I wrote up there makes sense. Any help is appreciated. I have the file zipped up if anyone would like to look at it.
 
Are you trying to just have one label that calculates the total sum of that TotalPay column?

Off the top of my head, one way you can do it is during ItemDataBound (it gets passed 'e', which is essentially a row in the datagrid, add the value that you want from that row (e.g. TotalSum+=e.item.cells(1)) to the sum, and set label to that value in the Page_Load.

Or something like that 🙂

I'm sure there are other ways too, but that is one suggestion.
 
Or alternately, depending on how you are storing the data (dataset, dataview, etc), you can iterate through that table separately and calculate the sum I would think, independent of the datagrid itself.
 
well my problem is in here....


Private Sub CalculatedFields()

Dim drArray() As DataRow
Dim pintTransactions As Integer
Dim pintCount As Integer
Dim dblTotalGrossPay As Double
Dim dblTotalWithholding As Double
Dim dblTotalNetPay As Double

dgPayrollInfo.ResetText()


drArray = DsPayrollEmployees1.tblEmployees(dgPayrollInfo.CurrentRowIndex). _
GetChildRows("tblEmployeestblPayroll")
pintTransactions = drArray.GetUpperBound(0) + 1
lblTransactions.Text = pintTransactions.ToString

For pintCount = 0 To drArray.GetUpperBound(0)
dblTotalGrossPay += (drArray(pintCount).Item("fldGrossPay"))
dblTotalWithholding += (drArray(pintCount).Item("fldWithholding"))
dblTotalNetPay += (drArray(pintCount).Item("fldNetpay"))
Next

lblTotalGrossPay.Text = dblTotalGrossPay.ToString
lblTotalWithholding.Text = dblTotalWithholding.ToString
lblTotalNetPay.Text = dblTotalNetPay.ToString

End Sub



when i click next or previous or first or last, etc.... currentrowindex is always staying at 0... giving me the same totals since it's accessing the 0, or 1st, record.

Any idea how to get the currentrow to change? or something else i could use?
 
Back
Top