• 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

    • I absolutely hate how they are using intentionally misleading wording to scare people into "upgrading" their operating system. They could use the money they are spending on marketing to keep Windows 10 running for, like, 10 more years.
    • Poorly or not, you're confronted to a decision when you visit this kind of website.
    • This tool is for ripping CDs not burning them. So it's to save cd audio tracks as files. Simple old tool to do it. For burning I used to use Nero Burning Tools back in the day rather than the ones you listed.
    • "The company has recently announced the forming of a new agentic AI team to develop an agentic AI framework for use in robotics." I wonder if any of their executives attented, "Microsoft Build 2025" last month?
    • Microsoft Build conference to leave Seattle after years in the city by Pradeep Viswanathan Microsoft Build is a flagship annual developer conference held by Microsoft since 2011. In 2017, Microsoft relocated Build from San Francisco to its home turf in Seattle. The proximity to its main campus allowed greater participation from its own engineers and executives, offering attendees a more integrated experience. Today, Jonathan Choe revealed on X that Microsoft has decided to move its Build developer conference out of Seattle. He discovered this information via an email sent by Visit Seattle to its members. Visit Seattle is a private, non-profit destination marketing organization that promotes travel to Seattle and King County. As a result of the move, Seattle-based hotels could lose approximately 9,314 room nights annually. Surprisingly, Visit Seattle’s message included several details about Microsoft’s reasons for the change. The primary reason appears to have come from within Microsoft itself. The company feels that Build lost momentum post-COVID, and the scheduling conflict with Google I/O, a competing event, has made it harder to attract the intended audience. Microsoft’s leadership believes they can better re-energize the program and boost attendance by moving it out of Seattle. The note even suggests that Build will likely be relocated to San Francisco or Las Vegas in 2026. Another factor contributing to the decision is the condition of the city. Last month, during the conference, Microsoft leadership and attendees walked between the Hyatt Regency and the Arch building on 8th Street. Reportedly, there were complaints about the general uncleanliness of the area, the visible presence of individuals using drugs, and unhoused individuals in a recurring tent in the Arch Tunnel. Visit Seattle believes these concerns also played a role in Microsoft’s final decision to relocate Build. Given Microsoft's high-profile presence and the economic impact of the event, this relocation may spark a political storm within the Seattle mayor’s office, drawing criticism over the city’s handling of downtown conditions.
  • Recent Achievements

    • One Year In
      Vladimir Migunov earned a badge
      One Year In
    • One Month Later
      daelos earned a badge
      One Month Later
    • Week One Done
      daelos earned a badge
      Week One Done
    • Mentor
      Karlston went up a rank
      Mentor
    • One Month Later
      EdwardFranciscoVilla earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      493
    2. 2
      snowy owl
      252
    3. 3
      +FloatingFatMan
      250
    4. 4
      ATLien_0
      220
    5. 5
      +Edouard
      169
  • Tell a friend

    Love Neowin? Tell a friend!