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. Advertisements

  2. Amelyan

    Guest Guest

    Guest, Mar 30, 2006
    #2
    1. Advertisements

  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.

    ...
     
    sloan, Mar 30, 2006
    #3
  4. Amelyan

    Guest Guest

    You are welcome.
     
    Guest, Mar 30, 2006
    #4
  5. Amelyan

    Bob DeVeaux

    Joined:
    Oct 13, 2006
    Messages:
    1
    Likes Received:
    0
    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
    Likes Received:
    0
    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
    Likes Received:
    0
    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
    Likes Received:
    0
    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
    Likes Received:
    0
    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
    Likes Received:
    0
    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.