Solved

DataGrid Row Count

Posted on 2004-09-22
6
455 Views
Last Modified: 2010-04-15
I assgned a empty DataTable as data Source to the Datagrid. Now i entered the data in
the datagrid rows and this data i want to assing to the datatable and then update to database
for this i want the rows count of the grid to know how much rows i entered in the grid and then
manually assign this griddata to that datatable by loop.... for this i dont know how
 I CAN GET THE ROW COUNT OF DATAGRID CONTROL ......

I also made type cast of datagrid to datatable and then tried to get count but in this way it
gives me the row count of that empty datatabel which i assigned to datagrid as datasource.

PLEASE REPLY ME AS SOON AS .... I STRUCKED AT THIS POINT  

0
Comment
Question by:TariqRahim
6 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 50 total points
ID: 12121384
Try this

datatable = datagrid.DataSource

count = datatable.rows.count();
0
 
LVL 6

Expert Comment

by:Chester_M_Ragel
ID: 12121560
Get the datasource of the Datagrid and cast that object to datatabel.
0
 
LVL 22

Expert Comment

by:Snarf0001
ID: 12137575
Is this web or windows?

If it's windows forms, you don't need to loop through and populate the datatable.  Once a grid is bound, everything you do on the grid is reflected in the bound datasource at the same moment, so your added rows will already be in there.

If it's aspx, it's DataGrid.Items.Count
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question