• 0

[ASP.NET 3.5] Custom Paging for ListView Control


Question

Hello,

I'm trying to create a custom paging for a ListView I have. I don't want to use Data Pager since it relies on the viewstate and I cannot afford to fetch all records at once (1 million++ records).

I tried to read a lot of this subject but I couldn't find anything that I can use. What I currently have (since the project is still in development and not production) is the data pager inside the Layout Template for the ListView Control.

Any helps, tips are welcomed. I'm completely stuck!

10 answers to this question

Recommended Posts

  • 0

Your problem doesn't lie within the pager. It lies in the records you are retrieving. By building a more efficient search filtering front end you can retrieve fewer, more relevant results.

Build a search criteria page to allow the user to restrict the results. If the dataset is merely informational data, then filter on a default such as limit to only current year, or 6 months, or top 500.

Not only will doing the above make the end user happy, but your DB server will thank you as well.

  • 0

In that case, I would have a talk with someone with knowledge on servers who is involved with the project.

Obtaining such results consumes the DB processing.

If I were stuck in such a scenario, I would still cheat. I would hide the pager. I would then create a series of buttons underneath the display such as:

"Pages 1-10" "1" "2" ... "10" "Pages 11-20"

Then only grab enough results to fill 10 pages (ex. 20 results per page x 10 pages = 200 results).

Upon clicking "Pages 11-20", query and filter so you get results 201-400, and change the text of the buttons.

  • 0

I actually found some code on the internet to deal with paging (a stored procedure that takes startIndex, maxdisplay ... etc ..) It worked fine, but when I use ObjectDataSource you need to supply the SelectCountMethod, and when do that the select parameters gets messed up (I think there is a bug or something since the data source cannot differentiate between the SelectMethod and the SelectCountMethod).

  • 0

Can we see what code you have so far, this works for me:

        <asp:ObjectDataSource 
            ID="ObjectDataSource1" 
            runat="server"
            EnablePaging="true"
            TypeName="Test.CustomerSelector"
            SelectMethod="GetPageOfCustomers"
            SelectCountMethod="GetCountOfCustomers"
            StartRowIndexParameterName="page"
            MaximumRowsParameterName="count" />

With an example selector:

    public class CustomerSelector
    {
        public List<Customer> GetPageOfCustomers(int page, int count)
        {
            return GetCustomers(count).ToList();
        }

        public int GetCountOfCustomers()
        {
            return 100;
        }

        private static IEnumerable<Customer> GetCustomers(int count)
        {
            for (int i = 0; i < count; i++)
                yield return CreateCustomer();
        }

        private static Customer CreateCustomer()
        {
            return new Customer { Title = "Mr", Forename = "Matthew", Surname = "Abbott" };
        }
    }

It's important to note that the function of the SelectCountMethod is not the same function as the SelectMethod, the SelectCountMethod simply gets the total number of entities. The SelectMethod is the method that you want called with your paging instructions.

  • 0

*BUMP*.

I'm sorry for this long delay. This IS NOT WORKING AT ALL :'(. Here's the damned error that I'm always getting:

[i]ObjectDataSource 'obj' could not find a non-generic method 'GetItemsCount' that has parameters: txtSearch, letter, displayType.[/i]

this is the code that I have:

the object data source:

	<asp:ObjectDataSource ID="obj" 
 	EnablePaging="true"
 	runat="server" 
 	SelectMethod="GetItems" 
 	SelectCountMethod="GetItemsCount" 
 	MaximumRowsParameterName="pageSize" StartRowIndexParameterName="startRowIndex"
 	TypeName="App_Code.Items">lt;SelectParameters>
 	<asp:ControlParameter ControlID="txtSearch" Name="txtSearch" PropertyName="Text" Type="String" />
 	<asp:ControlParameter ControlID="menu" Name="letter" PropertyName="SelectedValue" Type="String" />
 	<asp:ControlParameter ControlID="chk" Name="displayType" PropertyName="SelectedValue" Type="String" />
 	</SelectParameters>
	</asp:ObjectDataSource>

function signature:

public List<object> GetItems(string txtSearch, string letter, string displayType, int startRowIndex, int pageSize)
{
}

public int GetItemsCount() { return 500; }

the stored procedure:

ALTER PROCEDURE [dbo].[GetTitles]

 	@Alpha nvarchar(255),
 	@Letter nvarchar(20),
 	@DisplayType nvarchar(20),
	 @startRowIndex int,
	 @pageSize int

The object data source is bound to a ListView control if that helps? I'm getting frustrated. HELP ME!!!!!!

  • 0
  On 24/05/2010 at 16:08, sbauer said:

Why are using an ObjectDataSource? Why don't you just code it yourself?

yeah, that's what I did :-). the problem is already solved, but I want to know why the ObjectDataSource is not differentiating between SelectMethod and SelectCountMethod. Is this a bug or something?

  • 0

I think the reason why it's having trouble, is that the two methods should be designed to accept the same parameters. E.g.

GetItems(string txtSearch, string letter, string displayType, int startRowIndex, int pageSize);

and

GetItemsCount(string txtSearch, string letter, string displayType);

The reason for this is you should expect the GetItemsCount method to process the same arguments as the GetItems method, because it should be providing a count of how many items the GetItems method should return. If you had a method which doesn't accept the same parameters, how can you know that the count being returned is the actual count of items from GetItems if it is not accepting the same arguments?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • The article clearly states multiple times that he will DONATE his wealth. There's no mention of any loan, but haters gonna hate. He doesn't need to do this, you know? He could just give all that money to his kids and call it a day.
    • highly doubt that, he's giving away his wealth, he's been doing it for years now
    • Might be just about usable in about 5 years.
    • New Outlook for Windows gets a major boost with June 2025 Update by Pradeep Viswanathan Despite widespread criticism, Microsoft has remained focused on replacing the classic Outlook for Windows with the new web-based Outlook app for everyone. Every month, Microsoft releases updates to the new Outlook app based on user feedback. Today, Microsoft released the June 2025 update for Outlook for Windows with several improvements, including some of the most requested features by Outlook users. With this latest update, Microsoft has improved support for .pst (Outlook Data File) files. You can now reply to and forward emails in a stored .pst file. Microsoft is also working on further improving support for .pst files in the new Outlook for Windows. If you're using the new Outlook app with your personal Microsoft account that has access to Copilot Pro or AI credits through a Microsoft 365 Personal or Family subscription, Copilot features will now be available even for other personal email accounts configured in the Outlook app. This Copilot sharing feature works with email addresses such as Outlook.com, Hotmail.com, Live.com, MSN.com, and third-party providers like Gmail, Yahoo, and iCloud. Microsoft has also added the ability to easily move emails between personal accounts. This feature is disabled by default for enterprise users, but admins can enable it if needed. With this update, Microsoft has increased the default mail sync window in offline mode from 7 days to 30 days. Additionally, you can now access search folders and cancel an email after selecting Send in offline mode. This new update also brings email coaching support through Copilot. Copilot can now suggest adjustments to tone, clarity, and reader sentiment before you hit Send. If you are annoyed with Copilot, you can now disable Copilot completely by going to the Copilot > Copilot control page in the Settings window. In this release, Microsoft has added the ability to add shared folders to your Favorites, making it easier to access content directly from the Favorites list. Finally, an "External" tag will be added to external contact suggestions that appear in the dropdown menu when entering contacts in the email compose form, helping you distinguish between your organization's and external contacts.
    • "give" I believe he will give loans and drown the countries in debt
  • Recent Achievements

    • Week One Done
      Adam Todd earned a badge
      Week One Done
    • Contributor
      Ed B went up a rank
      Contributor
    • One Month Later
      moporcho earned a badge
      One Month Later
    • One Month Later
      Parotel earned a badge
      One Month Later
    • Reacting Well
      Cryptecks earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      211
    2. 2
      snowy owl
      156
    3. 3
      ATLien_0
      134
    4. 4
      Xenon
      120
    5. 5
      +FloatingFatMan
      113
  • Tell a friend

    Love Neowin? Tell a friend!