Solved

Return total number of records from a paged gridview

Posted on 2007-11-28
5
1,215 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
ID: 20366874
myGridView.Rows.Count
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20366883
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
ID: 20366903
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
ID: 20372369
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
ID: 20375049
>>>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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

912 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

17 Experts available now in Live!

Get 1:1 Help Now