To provide custom navigation controls
1. Add server controls to the Web Forms page that the user can use to navigate. For example, you may want to create ImageButton controls with forward and reverse images on them.
2. In the event handlers for the navigation controls, set the DataGrid control's CurrentPageIndex property to the page to go to, and then rebind the grid to the data source.
The below snippet shows how you can create code for a custom navigation panel that allow the user to go to the first, last, previous, or next page. The paging elements are defined as <asp:Button> controls whose CommandArgument property is set to indicate what page they go to. All four buttons call the following method when they are clicked.
Code:
void setPageCustom ( object src, EventArgs e ) {
// used by custom paging UI
string direction = ( ( Button ) sender ).CommandArgument;
switch ( direction ) {
case ( "first" ) :
myGrid.CurrentPageIndex = 0;
break;
case ( "prev" ) :
if ( myGrid.CurrentPageIndex > 0 )
myGrid.CurrentPageIndex --;
break;
case ( "next" ) :
if ( myGrid.CurrentPageIndex < ( myGrid.PageCount - 1 ) )
myGrid.CurrentPageIndex ++;
break;
case ( "last" ) :
myGrid.CurrentPageIndex = ( myGrid.PageCount - 1 );
break;
}
BindGrid ( );
}
Bookmarks