Click here to Skip to main content
12,243,303 members (22,814 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Dim Gross As Decimal = 0
Dim i As Integer = 0
If (DataGridView1.Rows.Count > 0) Then
For i = 0 To DataGridView1.Rows.Count
Gross = Gross + Convert.ToDecimal(((lblAmount)DataGridView1.Rows[i].FindControl("lblAmount")).Text.ToString())
End If

I used above code for display total of Amount column in data gridview in label.

Gross = Gross + Convert.ToDecimal(((lblAmount)DataGridView1.Rows[i].FindControl("lblAmount")).Text.ToString())
on highlighted part system gives an error ')' expected.I am using

Please give me correct syntax.
Posted 6-Dec-12 4:12am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Convert.ToDecimal(DirectCast(DataGridView1.Rows(i).FindControl("lblAmount"), lblAmount).Text.ToString())

I m not 100% sure but try using above stmt.
Yogi ,Pune 6-Dec-12 9:34am
Thanks for suggestion.

but now I am getting another error : "FindControl" is not a member of system.Windows.Forms.DataGridView.Row.

Why you use lblAmount 2nd time after breaket closed.Is it label or variable.
Member 9581488 6-Dec-12 9:42am
does it work if you remove second lblamount?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100