Solved

Return total number of records from a paged gridview

Posted on 2007-11-28
5
1,214 Views
Last Modified: 2009-10-26
hi, ive got a gridview and im usiging paging. I can get the total number of records in the gridview
in the selected event of the objectdatasource :
CType(e.ReturnValue, DataTable).Rows.Count)

ive got a textbox where the user can filter a value from the grid. Im using the FilterExpression method of the objectdatasource. But i cannot get the records returned by the filter.
Any ideas????

thanks!
0
Comment
Question by:arcross
  • 4
5 Comments
 
LVL 7

Expert Comment

by:nisarkhan
Comment Utility
myGridView.Rows.Count
0
 
LVL 7

Expert Comment

by:nisarkhan
Comment Utility
if you need all records then 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
0
 
LVL 7

Expert Comment

by:nisarkhan
Comment Utility
other way of doing is:

// If your datasource is DataSet

DataSet ds=new DataSet();

ds=GetRecords(); // Retrieveing records from database

lblRecords.Text=ds.Tables[0].Rows.Count; // this is your label displaying total records
Gridview1.DataSource=ds;

Gridview1.DataBind();

0
 
LVL 8

Author Comment

by:arcross
Comment Utility
hi nisarkhan,
If  I use gridview.rows.count. It will show me only the records for the page of the grid Im in. I want the total number of records after ive filtered using the .ExpresionFilter method of the Objectdatasource. I can get the total records using "CType(e.ReturnValue, DataTable).Rows.Count)"

but that doesnt gave me the records filtered.

any ideas?
0
 
LVL 7

Accepted Solution

by:
nisarkhan earned 500 total points
Comment Utility
>>>If  I use gridview.rows.count. It will show me only the records for the page of the grid

try this.

// If your datasource is DataSet

DataSet ds=new DataSet();

ds=GetRecords(); // Retrieveing records from database

lblRecords.Text=ds.Tables[0].Rows.Count; // this is your label displaying total records
Gridview1.DataSource=ds;

Gridview1.DataBind();
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now