1

I am using a GridView to display data from database. Using ASP.Net 4.0 with C#. The GV is given DataTable as its data source. I need to display numerical paging to this grid where the user can see Next and Previous buttons along with "page number links" like

<< Prev 1 2 3 ... Next >>

on top right section of the grid. Is there any way to do this using custom paging or any built in feature of GV? What kind of event I need to handle for the page number clicks? Can anybody please point me to right direction or code snippet?

Thanks ...

David Hall
  • 32,624
  • 10
  • 90
  • 127
Anil Soman
  • 2,443
  • 7
  • 40
  • 64

2 Answers2

2
 `allowpaging="true"` in gridview

then write you pagersettings as

<pagersettings mode="NumericFirstLast"
            firstpagetext="First"
            lastpagetext="Last"
            pagebuttoncount="5"  
            position="Bottom"/> 

you can see detail here

(Optional) on server side

place your page change logic in PageIndexChanged

Raab
  • 34,778
  • 4
  • 50
  • 65
1
  1. Set AllowPaging property to true.

  2. Set GridView.PagerSettings.Mode = PagerButtons.NumericFirstLast

  3. Set position="Top" and add the following to markup

    <PagerStyle HorizontalAlign="Right" /> 
    
  4. Attach to the PageIndexChanged event to handle page numeric clicks

Here is good example.

You can find more details here: http://msdn.microsoft.com/en-us/library/5aw1xfh3.aspx

k0stya
  • 4,267
  • 32
  • 41