• 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

    • AMD preps Ryzen 9600X3D for those who want a taste of the fastest gaming CPU for cheap by Sayan Sen AMD desktop processors are available across two platforms: socket AM4 and socket AM5. Both of these sockets are still going pretty strong, and the company is offering deals and discounts for both as it continues to release new SKUs for its older platform. For example, the company launched an affordable X3D processor for AM4 this month with the new 5500X3D. These gaming CPUs from AMD have been a massive success, as both AM4 and AM5 X3D chips are quite popular among gamers, and for good reason, too. They are fast, very fast. The massive chunk of vertical 3D stacked last-level cache (LLC) Level 3 cache helps these processors a ton in scenarios such as gaming. In our Ryzen 9 9950X3D review, we saw that 300+ frames per second are possible depending on the game title. While we did not review the 8-core 9800X3D, it has been found to be even slightly faster than the 9950X3D and is currently the most powerful gaming CPU on the planet. The Ryzen 9 9800X3D is selling these days for around $440-$500, and that may still be out of budget for many users. As such, similar to the 5600X3D, which is a 6-core 5000X3D processor cut down from the 8-core 5800X3D, AMD is planning to launch a hexacore Ryzen 5 9600X3D that will have two cores disabled compared to the 9800X3D. The information has been uncovered from the recent system integrator (SI) graphics driver for the recently launched Radeon AI PRO R9700 discrete GPU. The driver (Windows SI Driver for Radeon AI PRO R9700, Version 25.10.13.01) confirms the existence of 9600X3D as well as a 9600 non-X SKU and several other Ryzen PRO 9000 CPUs. The full list of upcoming CPUs is given below: Ryzen 5 9600X3D Ryzen 5 9600 AMD Ryzen 9 PRO 9945 Ryzen 7 PRO 9745 Ryzen 5 PRO 9645 Ryzen 5 PRO 9400 In terms of specs, the core configuration of the 9600X3D will be identical to the Ryzen 9600X and 9600, barring things like clock speeds. However, the six-core X3D will have a lot more L3 cache at 96 MB vs 32 MB on the 9600X and 9600. There is no information on pricing at the moment. Source: AMD (spotted by Mellodic Warrior on X)
    • With the dwindling number of TV license payers the BBC has to look for alternative avenues for income.
    • Bet they remove some sound card, wifi and bluetooth drivers that are still used today in some prebuilts. Seen some very old drivers still being used for those components. Printers can be bad also with very outdated but still working drivers.
    • If its anything like the TV licence they will send a few men around knocking and a letter every week saying they will take you to court.
    • New leak shows the design of the upcoming Nothing Headphone (1) by David Uzondu We've been hearing about the Nothing Headphone (1) for a while now, and it looks like we finally have our first real look at the headphones. In a new series of images leaked by @nothing_fan_blog on Instagram, the self-proclaimed "official German Nothing Fanpage", we can see Nothing's first over-ear headphones out in the wild. You definitely will not mistake these for anything else on a store shelf. The design has the company's signature see-through aesthetic, with a transparent oval piece on top of a solid rectangular base on the earcups, with three physical buttons for controls. Image via @nothing_fan_blog The headphones are set to launch alongside the Phone (3), which itself is getting rid of the glyph interface that made the company's phones stand out in the first place. It is a bit interesting seeing the new headphones establishing a strong visual identity while the flagship phone abandons its own. There is good news for anyone who values a wired connection for audio quality, as one of the images confirms the presence of a 3.5mm headphone jack. On the other hand, a close-up of the headband shows no visible folding hinges, which could be a minor inconvenience for some people, especially travelers. Image via @nothing_fan_blog As for colors, the leaks reveal both a white and black version. There's reportedly a gray option, but the leaked images did not show that. The more interesting part is the price, which is rumored to come in around $299 in the US and €299 in Europe. This would place the Headphone (1) in a very aggressive position, undercutting top-tier options from Sony and Bose by a significant margin. To compete, they will have to pack in the usual like Active Noise Cancellation. The sound quality also needs to be excellent, so let's hope the previously announced partnership with British audio company KEF works out well. We still don't have other details like battery life or specific driver information. Full details are expected at the official launch event, happening on July 1.
  • Recent Achievements

    • Week One Done
      Crunchy6 earned a badge
      Week One Done
    • One Month Later
      KynanSEIT earned a badge
      One Month Later
    • One Month Later
      gowtham07 earned a badge
      One Month Later
    • Collaborator
      lethalman went up a rank
      Collaborator
    • Week One Done
      Wayne Robinson earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      674
    2. 2
      ATLien_0
      274
    3. 3
      Michael Scrip
      219
    4. 4
      +FloatingFatMan
      170
    5. 5
      Steven P.
      161
  • Tell a friend

    Love Neowin? Tell a friend!