Getting all the datagrid rows

  • Thread starter Thread starter Mario Vargas
  • Start date Start date
M

Mario Vargas

Hi,

I have a datagrid which has many pages (10 rows per page)
and when I loop through the rows, I only get 10 rows (the
rows that are currently showed in the current page) How
can I get the total number of rows in all the pages?
Changing the current page and executing teh Databind()
method? Is there another way without having to query the
DB again?

Thanks in advance.

God Bless.
 
Could you loop the grid's datasource instead?

Dim dv As New DataView()
Dim drv As DataRowView
Try
dv = CType(dgMyDataGrid.DataSource, DataView)
For Each drv In dv
' do my thing here
Console.WriteLine(CStr(drv(0)))
Next

Return True
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical)
Finally
dv = Nothing
drv = Nothing
End Try
 
I was trying to avoid this, but it seems it's the only way
I have. One more question: Is the property DataSource
always available (after the method DataBind is called)? I
was trying to pass this property as a parameter to a
function to loop it, but it was set to nothing... Any
ideas?

Thanks in advance.
 
The .PageCount property of your datagrid will tell you how many pages
there are for the current RowCount setting.

So, 10 rows per page and 9 pages would be 91 - 100 records.

Is that any help?

You can also just run a quick SELECT COUNT query against your
datasource to get the number of records.
 
Back
Top