• 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">
 	<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

    • "Asus points out the security aspect, that you will lose support and thus there will be no security updates leaving your system exposed" Both Microsoft and 0patch offer ongoing security patches for a fee. https://learn.microsoft.com/en...w/extended-security-updates https://blog.0patch.com/2024/0...windows-10-with-0patch.html
    • I won't switch to W11 at home until I absolutely have to. This deadline depends on how long third-party software will be supported on W10 (such as browsers and image viewers and so on). I estimate that migration will be necessary around 2028, when the ESU program expires, but we'll see.
    • "not so intelligent after all" may be the best summary of this whole mess. And yeah, those opt-outs are practically hidden like Easter eggs, if you're lucky enough to even find them.
    • Asus joins Microsoft, AMD, Dell, urges you to "prepare for mandatory Windows 11 upgrade" by Sayan Sen Sometime earlier this year, Microsoft quietly updated the minimum CPU requirements guidance for Windows 11 24H2. Neowin noticed the change this past week as the support document now classifies a family of CPUs from each vendor, AMD, Intel, and Qualcomm, such that users find it easier to make out which processors are capable of being Copilot+ PC certified. Major OEM and hardware manufacturer Asus recently published a couple of blog posts regarding the upcoming Windows 10 end of support. The company says that it is now time to "prepare for the mandatory Windows 11 upgrade" by taking "essential steps." It writes: "With a mandatory Windows update on the horizon, there are essential steps you should take to ensure a smooth upgrade experience. Proper preparation will not only safeguard your files and system but will also allow you to take full advantage of the innovative features Windows 11 has to offer..." If you are on Windows 10 and are wondering why should you even bother upgrading, Asus points out the security aspect, that you will lose support and thus there will be no security updates, leaving your system exposed. The firm is certainly right, there are real dangers out there. For example, the Lumma infostealer impacted over 394,000 PCs worldwide (download this Defender definition for new ISO installations). Even official Windows files and folders can be vulnerable as we saw with the inetpub folder. However, Asus wants you to get excited about Copilot, the new AI assistant that Microsoft has been busy pushing everywhere on its apps and services. Echoing the same sentiment as Microsoft, and others like Dell and AMD, Asus says Copilot is what sets Windows 11 apart from 10 as it writes: "What makes Windows 11 different? One word: Copilot. ... If you’ve ever wished your computer could just “do the thing” you’re trying to describe — Copilot is your new best friend." Asus also says that you will be making the "smart move" by switching to Windows 11 now from 10. In the blog post under a subheading titled "It’s Not Just an Upgrade, It’s a Smart Move." The Taiwanese firm writes, "Upgrading to Windows 11 isn’t just about staying current ― it’s also about staying safe, working smarter, and getting more out of your computer every day." As such, the company also published a guide on how to proceed with the upgrade. Do you agree with Asus? When are you upgrading? Let us know below!
  • Recent Achievements

    • Posting Machine
      Fiza Ali earned a badge
      Posting Machine
    • One Year In
      WaynesWorld earned a badge
      One Year In
    • First Post
      chriskinney317 earned a badge
      First Post
    • Week One Done
      Nullun earned a badge
      Week One Done
    • First Post
      sultangris earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      180
    2. 2
      snowy owl
      130
    3. 3
      ATLien_0
      127
    4. 4
      Xenon
      118
    5. 5
      +Edouard
      91
  • Tell a friend

    Love Neowin? Tell a friend!