.NET
  Home arrow .NET arrow Page 2 - Return of the DataGrid: Paging and Editing...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Return of the DataGrid: Paging and Editing Explained
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 24
    2004-05-05

    Table of Contents:
  • Return of the DataGrid: Paging and Editing Explained
  • Paging
  • Editing
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Return of the DataGrid: Paging and Editing Explained - Paging


    (Page 2 of 4 )

    “Umm, what is paging?” you ask. Simply put, it is the means by which we can apportion our data into chunks and deliver them a piece at a time. A good example of this is a Google search. By default you receive 10 search results at a time, or 'per page'. Then you have the ability to see the next ten results, the next 'page' of results.

    We can and should apply the same methodology in our applications. Why? Well, suppose you're building an application to manage inventory. What are the chances of having only four pieces of inventory in total? I would guess that it's roughly about the same probability of me finding a million bucks in the mail tomorrow. Not null, just very improbable. For example, an inventory app I worked on for a company of only 200 employees has thousands of entries being tracked. Picture surfacing all entries at once, and you quickly understand the usefulness of paging. The same holds true for forums, e-commerce website, etc.

    With ASP, creating paging involved a mix of server and client-side scripting, and was just a pain to implement, maintain, and reuse. ASP.Net solves all that. In fact, you won't believe just how easy this is. I'm hoping that you still have the basic code in mind or in an IDE to work with because I'm not going to retype it; I'm just going to start adding in the new pieces. The first thing we do is modify our DataGrid itself:



    <asp:DataGrid id="dgSocks" runat="server"

    AllowPaging
    ="true" OnPageIndexChanged="pager" PageSize="3" >


    This is fairly straightforward. We are just saying that we want to allow paging, what exactly we want to do when the page index changes (a subroutine called “pager”), and defining the default number of results to return per page.

    You can combine this with any other options, such as sorting. But just make sure that you have set the AutoGenerateColumns property to to true, so that .NET knows to handle it.

    It's good to know exactly what is going to be produced here. Basically, you can expect an additional row added to th bottom of your table (grid). At the left side of the row will be two arrows (< & >) indicating that you can advance or retreat to another page. Now most likely you are as unsatisfied with default settings as I am, so thankfully we have a good degree of customizability (I think I may have just invented a word) available to us. We could easily center the arrows by adding the following:



    PagerStyle-HorizontalAlign="center"


    We may also come to the conclusion that the arrows just won't cut it, we want to know exactly where we are, we want numbered pages. Well hold on to your hat, because you're about to be blown away by the immense amount of extra code thats required:

    PagerStyle-Mode="NumericPages"

    Wow, was that ever difficult?! It took all of let's see, about 30 characters? I can almost hear you singing your paean to Microsoft already! Oh, but it gets better still; let me show you the editing capabilities!

    More .NET Articles
    More By Justin Cook


     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT