Getting all the datagrid rows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mario Vargas

    #1

    Getting all the datagrid rows

    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.
  • Slonjo

    #2
    Re: Getting all the datagrid rows

    Could you loop the grid's datasource instead?

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

    Return True
    Catch exc As Exception
    MsgBox(exc.Mess age, MsgBoxStyle.Cri tical)
    Finally
    dv = Nothing
    drv = Nothing
    End Try

    Comment

    • Mario Vargas

      #3
      Re: Getting all the datagrid rows

      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.
      [color=blue]
      >-----Original Message-----
      >Could you loop the grid's datasource instead?
      >
      > Dim dv As New DataView()
      > Dim drv As DataRowView
      > Try
      > dv = CType(dgMyDataG rid.DataSource,[/color]
      DataView)[color=blue]
      > For Each drv In dv
      > ' do my thing here
      > Console.WriteLi ne(CStr(drv(0)) )
      > Next
      >
      > Return True
      > Catch exc As Exception
      > MsgBox(exc.Mess age, MsgBoxStyle.Cri tical)
      > Finally
      > dv = Nothing
      > drv = Nothing
      > End Try
      >.
      >[/color]

      Comment

      • Chuck Grimsby

        #4
        Re: Getting all the datagrid rows

        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.


        "Mario Vargas" <mariovargas@vi abcp.com> wrote in message news:<064b01c33 fdf$cb4a31c0$a0 01280a@phx.gbl> ...[color=blue]
        > 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.[/color]

        Comment

        Working...