Click here to Skip to main content
14,828,871 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
what is the code for count the total number of rows in a datagrid using c#, displaying the total number in the label. when u click the button search must return the number of rows found in the lable not return 0 (zero).
Posted
Comments
Mehdi Gholam 31-Oct-11 5:43am
   
WEB, WPF, WinForms, Which?

It works ,if you are using datagridview in windows application
C#
lbl_row.Text = dataGridView1.RowCount.ToString();
   
for Winforms, its:
C#
datagridview.Rows.Count


For silverlight DataGrid, refer this : How do I get Silverlight Datagrid row count after grid is loaded?[^]
and this: Silverlight DataGrid Row count[^]
   
Use Property of RowCount to get the number of rows in a Data Grid View.
see the code below
C#
int noOfRows = dataGridView1.RowCount;
MessageBox.Show(noOfRows.ToString());
   
Comments
CHill60 29-Jul-15 9:42am
   
As posted in Solution 1 over 3 years ago!

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900