Thanks for all your help. I finally found the solution, shown below.
NOTES:
1) DataPager1 is ListView Control and is rendered inside the ListView.
2) Copy the DataPager to create a second DataPager DataPager2 outside of and below the ListView.
Remove MaxSize Property and all DataPager Fields and add Property to DataPager: PagedControlID="ListView1"
3) Use the ListView_DataBound Event shown below.
3) Set the ListView.Datasource = null in the Page_Load Event. This is necessary to prevent the ListView
from displaying Max Size empty rows after the Datasource is cleared and the page is submitted again
by clicking on the [Clear Selection] Button and the ListView should return no records.
DeepPowder
Member
173 Points
362 Posts
ListView with DataPage How to count all records not just displayed page
Nov 07, 2012 02:34 PM|LINK
I would like to return the total number of records in a ListView that has a DataPager control. If I use
Int32 numRecs = ListView1.Items.Count
I get the number of records on the current page, not all the records.
What is the best way to get the total number of records in a ListView?
Thanks for your help
spapim
Contributor
2686 Points
393 Posts
Re: ListView with DataPage How to count all records not just displayed page
Nov 07, 2012 03:32 PM|LINK
Hi,
Not sure, but try using the property TotalRowCount from DataPager.
Hope this helps.
www.imobiliariasemsuzano.com.br
DeepPowder
Member
173 Points
362 Posts
Re: ListView with DataPage How to count all records not just displayed page
Nov 07, 2012 03:41 PM|LINK
Thanks for your reply. I found this too and I'm trying to get it to work. Here's my code
DataPager dtp1 = (DataPager) ListView1.FindControl("DataPager1');
Int32 numRecs = dtp1.TotalRowCount;
THe code fails on the second line. It doesn't like dtp1.
Any suggestions?
Madhu1234
Participant
1380 Points
287 Posts
Re: ListView with DataPage How to count all records not just displayed page
Nov 07, 2012 03:55 PM|LINK
Check this link...
http://forums.asp.net/t/1440896.aspx/1
spapim
Contributor
2686 Points
393 Posts
Re: ListView with DataPage How to count all records not just displayed page
Nov 07, 2012 03:57 PM|LINK
I believe it will be necessary to declare the DataPager out of ListView.
www.imobiliariasemsuzano.com.br
oned_gk
All-Star
36280 Points
7394 Posts
Re: ListView with DataPage How to count all records not just displayed page
Nov 08, 2012 01:07 AM|LINK
You can get the total using the datasource
Suwandi - Non Graduate Programmer
DeepPowder
Member
173 Points
362 Posts
Re: ListView with DataPage How to count all records not just displayed page
Nov 08, 2012 04:17 PM|LINK
Thanks for all your help. I finally found the solution, shown below.
NOTES:
1) DataPager1 is ListView Control and is rendered inside the ListView.
2) Copy the DataPager to create a second DataPager DataPager2 outside of and below the ListView.
Remove MaxSize Property and all DataPager Fields and add Property to DataPager: PagedControlID="ListView1"
3) Use the ListView_DataBound Event shown below.
3) Set the ListView.Datasource = null in the Page_Load Event. This is necessary to prevent the ListView
from displaying Max Size empty rows after the Datasource is cleared and the page is submitted again
by clicking on the [Clear Selection] Button and the ListView should return no records.
protected void ListView1_DataBound(object sender, EventArgs e)
{
DataPager dtp1 = (DataPager)ListView1.FindControl("DataPager1");
DataPager dtp2 = (DataPager)DataPager2;
Int32 numRecs = (Int32)dtp2.TotalRowCount;
String sMsg = "";
if ((dtp1 == null) ||(numRecs == 0))
{
sMsg = "Enter Selection Criteria and click [Show Selection] Button. ";
}
else if (numRecs == 1)
{
sMsg = "1 record found. ";
}
else
{
sMsg = numRecs + " records found. ";
}
lblMessage.Text = sMsg;
}