Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView: Total Records

Reply
Thread Tools

GridView: Total Records

 
 
Amelyan
Guest
Posts: n/a
 
      03-30-2006
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,




 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      03-30-2006
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/...w/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,
>
>
>
>
>

 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      03-30-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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/...w/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,
> >
> >
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      03-30-2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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/...w/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,
> > >
> > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Bob DeVeaux Bob DeVeaux is offline
Junior Member
Join Date: Oct 2006
Posts: 1
 
      10-13-2006
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!
 
Reply With Quote
 
llemnus llemnus is offline
Junior Member
Join Date: Aug 2007
Posts: 1
 
      08-28-2007
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.
 
Reply With Quote
 
minessence minessence is offline
Junior Member
Join Date: Dec 2008
Posts: 1
 
      12-15-2008
Quote:
Originally Posted by Bob DeVeaux
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.ObjectDataSourceStatusEv entArgs) 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.
 
Reply With Quote
 
shravaniraj shravaniraj is offline
Junior Member
Join Date: Mar 2009
Posts: 1
 
      03-24-2009
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,
 
Reply With Quote
 
NMC NMC is offline
Junior Member
Join Date: Jul 2009
Posts: 1
 
      07-17-2009
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
 
Reply With Quote
 
AngelaG AngelaG is offline
Junior Member
Join Date: Oct 2011
Posts: 1
 
      10-24-2011
Quote:
Originally Posted by =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= View Post
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/...w/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!!
 
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
BT Total Broadband vs BT Business Total John Y UK VOIP 2 02-02-2007 09:27 AM
Total number of records paged gridview msch-prv@bluewin.ch ASP .Net 2 08-23-2006 07:41 AM
ASP.NET: Repeater: Total no. of Records in Footer Sachin ASP .Net 2 03-05-2006 05:45 PM
How to get the total number of queried records? Quentin Huo ASP .Net 5 09-01-2004 10:53 PM
How to know total records selected? anand ASP .Net 4 06-17-2004 07:03 AM



Advertisments