• 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

    • NTLite 2025.06.10459 is out.
    • Wireshark 4.4.7 by Razvan Serea  Wireshark is a network packet analyzer. A network packet analyzer will try to capture network packets and tries to display that packet data as detailed as possible. You could think of a network packet analyzer as a measuring device used to examine what's going on inside a network cable, just like a voltmeter is used by an electrician to examine what's going on inside an electric cable (but at a higher level, of course). In the past, such tools were either very expensive, proprietary, or both. However, with the advent of Wireshark, all that has changed. Wireshark is perhaps one of the best open source packet analyzers available today. Deep inspection of hundreds of protocols, with more being added all the time Live capture and offline analysis Standard three-pane packet browser Multi-platform: Runs on Windows, Linux, OS X, Solaris, FreeBSD, NetBSD, and many others Captured network data can be browsed via a GUI, or via the TTY-mode TShark utility The most powerful display filters in the industry Rich VoIP analysis Read/write many different capture file formats Capture files compressed with gzip can be decompressed on the fly Live data can be read from Ethernet, IEEE 802.11, PPP/HDLC, ATM, Bluetooth, USB, Token Ring, Frame Relay, FDDI, and others (depending on your platfrom) Decryption support for many protocols, including IPsec, ISAKMP, Kerberos, SNMPv3, SSL/TLS, WEP, and WPA/WPA2 Coloring rules can be applied to the packet list for quick, intuitive analysis Output can be exported to XML, PostScript®, CSV, or plain text Wireshark 4.4.7 changelog: The following vulnerabilities have been fixed wnpa-sec-2025-02 Dissection engine crash. Issue 20509. CVE-2025-5601. The following bugs have been fixed Wireshark does not correctly decode LIN "go to sleep" in TECMP and CMP. Issue 20463. Dissector bug, Protocol CIGI. Issue 20496. Green power packets are not dissected when proto_version == ZBEE_VERSION_GREEN_POWER. Issue 20497. Packet diagrams misalign or drop bitfields. Issue 20507. Corruption when setting heuristic dissector table UI name from Lua. Issue 20523. LDAP dissector incorrectly displays filters with singleton "&" Issue 20527. WebSocket per-message compression extentions: fail to decompress server messages (from the 2nd) due to parameter handling. Issue 20531. The LL_PERIODIC_SYNC_WR_IND packet is not properly dissected (packet-btle.c) Issue 20554. Updated Protocol Support AT, BT LE LL, CIGI, genl, LDAP, LIN, Logcat Text, net_dm, netfilter, nvme, SSH, TCPCL, TLS, WebSocket, ZigBee, and ZigBee ZCL Download: Wireshark 4.4.7 | 83.2 MB (Open Source) Download: Portable Wireshark 4.4.7 | ARM64 Installer View: Wireshark Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Snapchat finally has a watchOS app, a decade after the Apple Watch launched by David Uzondu Snap has announced that Snapchat is finally hopping onto Apple Watch, something many users have probably been waiting for. This new app lets you easily preview an incoming message right on your wrist and then fire back a reply without ever needing to grab your iPhone. For those quick responses, you have options: you can tap out a message on the keyboard, use Scribble to draw letters, dictate your reply, or just send a fitting emoji. Snap says it's trying to make Snapchat easier to use on all the different devices people have in their lives. It's already seen people using Snapchat on tablets and the web, so bringing it to wearables like the Apple Watch feels like the next natural move. That marks a big change from back in 2015 when the Apple Watch first launched. At the time, Snap took a more cautious "wait and see" approach, wanting to see if people actually used smartwatches before building an app. New app launches are not always perfect. It is still early days for the watchOS app, as some users on Reddit have reported the app being stuck on the loading screen. Hopefully, Snap will address these initial teething problems quickly. This expansion to Apple Watch comes after the company abandoned its widely criticized three-tab app redesign following a notable drop in its North American daily active users and significant negative feedback. That redesign, introduced back in September 2024, was meant to simplify things but ended up frustrating many, leading Snap to reverse course after about seven months and work on a refined five-tab layout. Meanwhile, Android smartwatch users with Wear OS are still in a different boat, as there is no official, dedicated Snapchat app for that platform yet. They can typically only receive notifications, and attempts to sideload the full Android app often result in a clunky experience.
    • I've asked Sayan to limit these articles to science tech news.
    • LeafView 3.6.4 by Razvan Serea LeafView is a fast, open-source image viewer built with Electron. It offers a sleek, minimal UI for fast and efficient image browsing. Supporting various formats, LeafView ensures a smooth viewing experience with essential features like zoom, rotation, and slideshow mode. Designed for simplicity and performance, it utilizes hardware acceleration for smooth rendering and supports touch gestures for seamless navigation. LeafView key features: Lightweight & Open-Source – Minimal resource usage with a clean, efficient design Electron-Based – Cross-platform compatibility with modern UI Multiple Image Format Support – Opens JPG, PNG, GIF, BMP, and more Smooth Rendering – Hardware acceleration for fast performance Essential Image Controls – Zoom, rotate, and slideshow mode Touch Gesture Support – Seamless navigation on compatible devices Minimal UI – Focused on simplicity and ease of use LeafView 3.6.4 changelog: Update electron to v36.4.0 Download: LeafView 3.6.4 | Portable | ~100.0 MB (Open Source) View: LeafView Website | Other operating systems | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Year In
      survivor303 earned a badge
      One Year In
    • Week One Done
      jbatch earned a badge
      Week One Done
    • First Post
      Yianis earned a badge
      First Post
    • Rookie
      GTRoberts went up a rank
      Rookie
    • First Post
      James courage Tabla earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      419
    2. 2
      +FloatingFatMan
      182
    3. 3
      snowy owl
      181
    4. 4
      ATLien_0
      174
    5. 5
      Xenon
      137
  • Tell a friend

    Love Neowin? Tell a friend!