Home
Manage Your Code
Snippet: Show GridView Caption (C#)
Title: Show GridView Caption Language: C#
Description: This method shows a gridview caption in the format "Showing X-Y of Z". Views: 148
Author: Dave Donaldson Date Added: 2/23/2008
Copy Code  
1public static void ShowGridCaption(GridView grid, int gridItemCount)
2{
3    string captionFormat = "Showing {0}-{1} of {2}";
4
5    // Make it easy because of the zero-based index

6    int previousPage = grid.PageIndex;
7    int currentPage = grid.PageIndex + 1;
8
9    // Do calculations

10    int pageEnd = (currentPage < grid.PageCount) ? (currentPage) * grid.PageSize : gridItemCount;
11    int pageStart = (previousPage * grid.PageSize) + 1;
12
13    grid.Caption = string.Format(captionFormat, pageStart, pageEnd, gridItemCount);
14    grid.CaptionAlign = TableCaptionAlign.Top;
15}