GridView: Total Records

A

Amelyan

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,
 
S

sloan

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.

...
 
Joined
Oct 13, 2006
Messages
1
Reaction score
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!
 
Joined
Aug 28, 2007
Messages
1
Reaction score
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.
 
Joined
Dec 15, 2008
Messages
1
Reaction score
0
Obtaining the total rows count of GridView

Bob DeVeaux said:
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!


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.
 
Joined
Mar 24, 2009
Messages
1
Reaction score
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,
 

NMC

Joined
Jul 17, 2009
Messages
1
Reaction score
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
 
Joined
Oct 24, 2011
Messages
1
Reaction score
0
Gridview Count

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,
>
>
>
>
>

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!!
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top