2

how to implement data pager in asp.net C# like below image?

enter image description here

royhowie
  • 11,075
  • 14
  • 50
  • 67
vir
  • 1,081
  • 4
  • 19
  • 31

5 Answers5

1

You can make use of Cutome paging and than you can do it there are no of example available on google for this ....

here is one for you : http://www.dotnetspeaks.com/DisplayArticle.aspx?ID=55#

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
1

I don't know if you use MVC, but when I did I used this tool: http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/ It worked out very good for me.

Johan
  • 1,094
  • 1
  • 8
  • 4
0

You can also use LINQ to achive paging:

paging example

amr-it
  • 21
  • 4
0
public class PagingInfo
{
    public int TotalItems { get; set; }
    public int ItemsPerPage { get; set; }
    public int CurrentPage { get; set; }        
    public int TotalPages
    {
        get { return (int)Math.Ceiling((decimal)TotalItems / ItemsPerPage); }
    }
    public int TotalDisplayPages { get; set; }
}

and then use this class in pagingHelper metioned below..

public static MvcHtmlString PageLinks(this HtmlHelper html,PagingInfo pagingInfo,Func<int,string>pageUrl)
    {
        var result = new StringBuilder();
        var start = pagingInfo.CurrentPage > 1 ? pagingInfo.CurrentPage - 1:pagingInfo.CurrentPage;
        var end = start + pagingInfo.TotalDisplayPages;
        for (var i = start; i <= end; i++)
        {
            var tag = new TagBuilder("a");                
            // Construct an <a> tag
            tag.MergeAttribute("href", "");

            tag.InnerHtml = (i).ToString();
            if (i == pagingInfo.CurrentPage)
                tag.AddCssClass("selected");
            result.AppendLine(tag.ToString());
        }
        return MvcHtmlString.Create(result.ToString());
    }
paramjeet singh
  • 165
  • 1
  • 10
0

you can select set of rows by row number http://support.microsoft.com/kb/186133 and by getting the whole row count you can determine how many pages you'll need after that not much programming JS C# and CSS you'll have even better than the image

Hilmi
  • 3,411
  • 6
  • 27
  • 55
  • Hi, thanks for reply I need something like < Last >> < Last >> what you have redirect me is like < Last >> I just want to show only 3 buttons in Paging... – vir Mar 17 '12 at 06:47
  • My friend its just "switch case" scenario, if Pages >3 show only the current page number and 2 more numbers, i used this approach i a website and its working perfectly!! – Hilmi Mar 18 '12 at 06:50
  • i'm not able to do that..:( could you post a code for that? thx – vir Mar 27 '12 at 05:29
  • sql : select rank() OVER (ORDER BY a.au_lname, a.au_fname) as rank,name from student where rank <10 and rank >5 /* depend on the current page */ ____________________________________ asp/C# in a fast way (i'll check it when i get home)... if (currentPage==1) startPageNumber=1; if (curentPage==LastPageNumber) startPage=LastPageNumber-2; if (LastPageNumber<3) startPageNumber=1; for(int i=startPageNumber;i<=startPageNumber+2;i++){ //create label/link button } //just check that we haf covered all cases sir, – Hilmi Mar 27 '12 at 06:33