GridView: Total Records

Discussion in 'ASP .Net' started by Amelyan, Mar 30, 2006.

  1. Amelyan

    Amelyan Guest

    I need to get the total number of items/records returned into GridView.

    If I just do myGridView.Rows.Count, then it just returns me the total number
    of items on the page.

    But if I have, 10 pages (10 records per page) and 98 records total,
    Rows.Count will return me 10 on the first 9 pages, and 8, on the last page.

    But, I need to somehow get access to total record count which is 98. What
    is the proper/easy way to accomplish that?

    Thanks,
    Amelyan, Mar 30, 2006
    #1
    1. Advertising

  2. You need to use the ReturnValue of the ObjectDataSourceStatusEventArgs or
    SqlDataSourceStatusEventArgs while handling the datasource's Selected event.
    Look at this sample for the code
    http://www.webswapp.com/codesamples/aspnet20/dropdownlist_gridview/default.aspx
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Amelyan" wrote:

    > I need to get the total number of items/records returned into GridView.
    >
    > If I just do myGridView.Rows.Count, then it just returns me the total number
    > of items on the page.
    >
    > But if I have, 10 pages (10 records per page) and 98 records total,
    > Rows.Count will return me 10 on the first 9 pages, and 8, on the last page.
    >
    > But, I need to somehow get access to total record count which is 98. What
    > is the proper/easy way to accomplish that?
    >
    > Thanks,
    >
    >
    >
    >
    >
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Mar 30, 2006
    #2
    1. Advertising

  3. Amelyan

    sloan Guest

    Phillip!

    Thank you,

    I have been looking for the Nested GridView sample (same web site, not the
    page you give) for a few weeks now.

    I didn't bookmark it, and figured I'd find it later.

    Too much info on the internet sometimes.

    ...



    "Phillip Williams" <> wrote in message
    news:...
    > You need to use the ReturnValue of the ObjectDataSourceStatusEventArgs or
    > SqlDataSourceStatusEventArgs while handling the datasource's Selected

    event.
    > Look at this sample for the code:
    >

    http://www.webswapp.com/codesamples/aspnet20/dropdownlist_gridview/default.aspx
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Amelyan" wrote:
    >
    > > I need to get the total number of items/records returned into GridView.
    > >
    > > If I just do myGridView.Rows.Count, then it just returns me the total

    number
    > > of items on the page.
    > >
    > > But if I have, 10 pages (10 records per page) and 98 records total,
    > > Rows.Count will return me 10 on the first 9 pages, and 8, on the last

    page.
    > >
    > > But, I need to somehow get access to total record count which is 98.

    What
    > > is the proper/easy way to accomplish that?
    > >
    > > Thanks,
    > >
    > >
    > >
    > >
    > >
    sloan, Mar 30, 2006
    #3
  4. You are welcome.
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "sloan" wrote:

    > Phillip!
    >
    > Thank you,
    >
    > I have been looking for the Nested GridView sample (same web site, not the
    > page you give) for a few weeks now.
    >
    > I didn't bookmark it, and figured I'd find it later.
    >
    > Too much info on the internet sometimes.
    >
    > ...
    >
    >
    >
    > "Phillip Williams" <> wrote in message
    > news:...
    > > You need to use the ReturnValue of the ObjectDataSourceStatusEventArgs or
    > > SqlDataSourceStatusEventArgs while handling the datasource's Selected

    > event.
    > > Look at this sample for the code:
    > >

    > http://www.webswapp.com/codesamples/aspnet20/dropdownlist_gridview/default.aspx
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "Amelyan" wrote:
    > >
    > > > I need to get the total number of items/records returned into GridView.
    > > >
    > > > If I just do myGridView.Rows.Count, then it just returns me the total

    > number
    > > > of items on the page.
    > > >
    > > > But if I have, 10 pages (10 records per page) and 98 records total,
    > > > Rows.Count will return me 10 on the first 9 pages, and 8, on the last

    > page.
    > > >
    > > > But, I need to somehow get access to total record count which is 98.

    > What
    > > > is the proper/easy way to accomplish that?
    > > >
    > > > Thanks,
    > > >
    > > >
    > > >
    > > >
    > > >

    >
    >
    >
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Mar 30, 2006
    #4
  5. Amelyan

    Bob DeVeaux

    Joined:
    Oct 13, 2006
    Messages:
    1
    I just thought I would post to say thank you also.

    I found your post very useful!

    This was the code I used:

    Private Sub odsCustomersList_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
    'notice that this datasource returns a DataView
    lblCount1.Text = "Total Record count in the dropdownlist above= " & CType(e.ReturnValue, DataView).Count.ToString()
    End Sub


    Thank you muchly!
    Bob DeVeaux, Oct 13, 2006
    #5
  6. Amelyan

    llemnus

    Joined:
    Aug 28, 2007
    Messages:
    1
    I used a different approach to get the total records number.
    Here is what I do:

    myGridView.DataSource = myDataSet;
    myGridView.DataMember = myDataSet.Tables[0];

    NrOfRecords = myDataSet.Tables[0].Rows.Count;

    For me it worked ok.
    llemnus, Aug 28, 2007
    #6
  7. Amelyan

    minessence

    Joined:
    Dec 15, 2008
    Messages:
    1
    Obtaining the total rows count of GridView


    Thanks, this worked well for me. I used:

    Protected Sub ObjectDataSourceEzine_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSourceEzine.Selected
    LabelGroupSize.Text = CType(e.ReturnValue, List(Of eZineRec)).Count.ToString()
    End Sub

    =====
    As you can see, the data source for my Gridview control was a user defined generic list.
    minessence, Dec 15, 2008
    #7
  8. Amelyan

    shravaniraj

    Joined:
    Mar 24, 2009
    Messages:
    1
    Hi,

    I am facing the same problem of not getting total row count..
    i am using a xmldatasource for the gridview.so please can you suggest me the code to get the total rowcount for the xmldatasource...
    i want to display for every page like "Viewing 1 to 10 of 14" on the top of the gridview.
    here page size is 10 and 14 is the total no.of records in the datasource.
    and for the next page i should display "Viewing 11 to 14 of 14".

    Thanks,
    shravaniraj, Mar 24, 2009
    #8
  9. Amelyan

    NMC

    Joined:
    Jul 17, 2009
    Messages:
    1
    Total record count of GridView

    Hi,

    I think we can simply have total record count as follow:
    On Page_Load() or somewhere
    MyGridView.AllowPaging = False
    ... Setup MyGridView and Bind Data...
    Get total record count:
    LblRecCount.Text = MyGridView.Rows.Count
    MyGridView.AllowPaging = True
    MyGridView.DataBind()

    Regards,
    NMC
    NMC, Jul 17, 2009
    #9
  10. Amelyan

    AngelaG

    Joined:
    Oct 24, 2011
    Messages:
    1
    Gridview Count

    Great Stuff! Thank you.
    When using SqldataSource, I used the following:

    <script runat="server">
    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
    MyBase.OnInit(e)
    AddHandler dsOrders.Selected, AddressOf dsOrders_Selected
    End Sub
    Private Sub dsOrders_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
    lblCount2.Text = e.AffectedRows.ToString() & " Outstanding Orders found."
    End Sub

    </script>

    It works very well!!
    AngelaG, Oct 24, 2011
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anand
    Replies:
    4
    Views:
    2,178
    anand
    Jun 17, 2004
  2. Quentin Huo
    Replies:
    5
    Views:
    503
    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=
    Sep 1, 2004
  3. Sachin
    Replies:
    2
    Views:
    3,514
    =?Utf-8?B?UyBQ?=
    Mar 5, 2006
  4. Replies:
    2
    Views:
    7,298
    Bruno Alexandre
    Aug 23, 2006
  5. Amelyan

    GridView: Total Records Count

    Amelyan, Mar 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    841
    Steve C. Orr [MVP, MCSD]
    Mar 31, 2006
Loading...

Share This Page