Total number of records paged gridview

Discussion in 'ASP .Net' started by msch-prv@bluewin.ch, Aug 23, 2006.

  1. Guest

    Hi, I have a paged gridview (Apts_grd) tied to an Access DataSource
    (Apts_srcGrd). How do I get the total number of data records returned
    by the query?

    The following shows only the number of records per page:

    Apts_srcGrd.SelectCommand = "SELECT * FROM tblApts WHERE ..."
    Apts_grd.DataBind()
    Response.Write("Count: " + Apts_grd.Rows.Count.ToString

    TIA, Mark
     
    , Aug 23, 2006
    #1
    1. Advertising

  2. -- Call ExecuteNonQuery to send command
    int count = (int)cmd.ExecuteScalar();

    The query in the SqlCommand constructor obtains the count of all records
    from a table. This query will only return a single value. The
    ExecuteScalar method returns this value. Since the return type of
    ExecuteScalar is type object, we use a cast operator to convert the value to
    int.
    Hope that helps
    Patrick

    <> wrote in message
    news:...
    > Hi, I have a paged gridview (Apts_grd) tied to an Access DataSource
    > (Apts_srcGrd). How do I get the total number of data records returned
    > by the query?
    >
    > The following shows only the number of records per page:
    >
    > Apts_srcGrd.SelectCommand = "SELECT * FROM tblApts WHERE ..."
    > Apts_grd.DataBind()
    > Response.Write("Count: " + Apts_grd.Rows.Count.ToString
    >
    > TIA, Mark
    >
     
    Patrick.O.Ige, Aug 23, 2006
    #2
    1. Advertising

  3. You can do that automatically,
    you always need to count records on the DataSet itself

    ---------------------------------------
    Sub BindSQL()
    Dim MyConnection As SqlConnection
    Dim DS as DataSet
    Dim MyCommand As SqlDataAdapter
    Dim RcdCount As Integer

    'Our SQL string
    Dim sqlStr As String = "SELECT titles.title, authors.au_lname, " & _
    "authors.au_fname, titles.price " & _
    "FROM authors INNER JOIN titleauthor ON " & _
    "authors.au_id = titleauthor.au_id " & _
    "INNER JOIN titles ON " & _
    "titleauthor.title_id = titles.title_id"

    'The connection to our database
    Dim strConn As String = "server=(local);uid=sa;pwd=;" & _
    "database=pubs;Trusted_Connection=yes;"

    'Open up our connection with our connection object
    MyConnection = New SQLConnection(strConn)

    'To execute our Sql Statement and provide our active connection
    MyCommand = NewSqlDataAdapter(sqlStr, MyConnection)

    'Create instance of DataSet object and fill our predetermined
    'datagrid with it and we name it
    DS = new DataSet()
    MyCommand.Fill(DS, "pubs")

    RcdCount = DS.Tables("pubs").Rows.Count.ToString()

    RecordCount.Text = "<b><font color=red>" & RcdCount & "</font> records
    found"

    Pubs.DataSource = DS
    Pubs.Databind()

    lblPageCount.Text = "Page " & Pubs.CurrentPageIndex + 1 & " of " &
    Pubs.PageCount
    End Sub
    ---------------------------------------

    you can see this link to have a better idea
    http://www.developerfusion.co.uk/show/4060/2/
    --

    Bruno Alexandre
    "a Portuguese in KĂžbenhavn, Danmark"
     
    Bruno Alexandre, Aug 23, 2006
    #3
    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. Quentin Huo
    Replies:
    5
    Views:
    518
    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=
    Sep 1, 2004
  2. Amelyan

    GridView: Total Records

    Amelyan, Mar 30, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    83,145
    AngelaG
    Oct 24, 2011
  3. Richard Pimentel

    Explorer navigation errors with non-paged or large paged DataGrid.

    Richard Pimentel, Dec 31, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    166
    Richard Pimentel
    Dec 31, 2003
  4. Amelyan

    GridView: Total Records Count

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

    total items in paged output

    Trapulo, Aug 31, 2007, in forum: ASP .Net Web Controls
    Replies:
    8
    Views:
    204
    Trapulo
    Sep 12, 2007
Loading...

Share This Page