Click here to Skip to main content
11,479,096 members (56,540 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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())
}
Next
}
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 VB.net.

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

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
Yogi ,Pune at 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 at 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
0 Sergey Alexandrovich Kryukov 215
1 F-ES Sitecore 195
2 OriginalGriff 165
3 Frankie-C 120
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,366
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2015
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