Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Total number of records paged gridview

Reply
Thread Tools

Total number of records paged gridview

 
 
msch-prv@bluewin.ch
Guest
Posts: n/a
 
      08-23-2006
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

 
Reply With Quote
 
 
 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      08-23-2006
-- 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

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
 
 
 
Bruno Alexandre
Guest
Posts: n/a
 
      08-23-2006
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"




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView: Total Records Amelyan ASP .Net 9 10-24-2011 09:55 AM
total items in paged output Trapulo ASP .Net Web Controls 8 09-12-2007 10:30 AM
GridView: Total Records Count Amelyan ASP .Net Web Controls 2 03-30-2006 11:20 PM
How to get the total number of queried records? Quentin Huo ASP .Net 5 09-01-2004 10:53 PM
Explorer navigation errors with non-paged or large paged DataGrid. Richard Pimentel ASP .Net Datagrid Control 0 12-31-2003 06:32 PM



Advertisments