How to create a PagerTemplate for the GridView control

The following is a very short example of how you can create your own PagerTemplate for the GridViewControl and adding server-side code blocks to the template.

<asp:GridView AllowPaging=True Id="GridView1" ...>
    Selected Index <%= GridView1.PageIndex * GridView1.PageSize %>
 Nunmber of pages <%=GridView1.PageCount %>

By using server-side code block within the template, you can create your own pager. If you want to add a First/Last or Next/Prev button, you simply add a Button control and set its CommandName to “First”, “Last”, “Next” or “Prev”. You don’t need to add any event that should handle the paging, the GridView will get the CommandName for the buttons you have pressed and do the action for you. To add numeric paging, you add Button controls where the CommandName should be set to “Page” and the CommandArgument to the index of the page to navigate to.

Next Post Previous Post
No Comment
Add Comment
comment url