Click here to Skip to main content
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 625
1 OriginalGriff 285
2 George Jonsson 225
3 CPallini 210
4 Fredrik Bornander 150
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,263
2 CPallini 4,750
3 George Jonsson 3,227
4 Gihan Liyanage 2,487


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2014
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