Click here to Skip to main content
11,709,844 members (52,419 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 3: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 514
1 OriginalGriff 250
2 Peter Leow 229
3 Maciej Los 185
4 Mika Wendelius 175
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web02 | 2.8.150819.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