Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,
I want to implement NumericFirstLast type pagination in the Repeater control which is available in GridView. It would be great if i get any help on this. As well as could you please tell me whether custom paging is possible with below type of pagination.

For Example,

First Previous 1 2 3 4 5 6... Next Last
Posted

Hi I think this might help you, I forgot link which i searched so pasting the code.


Step 1: add Following in your aspx.

ASP.NET
<asp:datalist cellpadding="5" repeatdirection="Horizontal" runat="server" id="dlPager" xmlns:asp="#unknown">
                        OnItemCommand="dlPager_ItemCommand">
                        <itemtemplate>
                            <asp:linkbutton enabled="<%#Eval("Enabled") %>" runat="server" id="lnkPageNo" text="<%#Eval("Text") %>">
                                CommandArgument='<%#Eval("Value") %>' CommandName="PageNo"></asp:linkbutton>
                        </itemtemplate>
                    </asp:datalist>


after getting dataset call this method and bind output to Datalist

C#
public List<listitem> GeneratePager(int totalRowCount, int pageSize, int currentPage)
        {
            int totalLinkInPage = 5;
            int totalPageCount = (int)Math.Ceiling((decimal)totalRowCount / pageSize);

            int startPageLink = Math.Max(currentPage - (int)Math.Floor((decimal)totalLinkInPage / 2), 1);
            int lastPageLink = Math.Min(startPageLink + totalLinkInPage - 1, totalPageCount);

            if ((startPageLink + totalLinkInPage - 1) > totalPageCount)
            {
                lastPageLink = Math.Min(currentPage + (int)Math.Floor((decimal)totalLinkInPage / 2), totalPageCount);
                startPageLink = Math.Max(lastPageLink - totalLinkInPage + 1, 1);
            }

            List<listitem> pageLinkContainer = new List<listitem>();

            if (startPageLink != 1)
                pageLinkContainer.Add(new ListItem("First", "1", currentPage != 1));
            for (int i = startPageLink; i <= lastPageLink; i++)
            {
                pageLinkContainer.Add(new ListItem(i.ToString(), i.ToString(), currentPage != i));
            }
            if (lastPageLink != totalPageCount)
                pageLinkContainer.Add(new ListItem("Last", totalPageCount.ToString(), currentPage != totalPageCount));

            return pageLinkContainer;

        } 
</listitem></listitem></listitem>


This is the event code
C#
protected void dlPager_ItemCommand(object source, DataListCommandEventArgs e)
     {
         try
         {
             if (e.CommandName == "PageNo")
             {
                 pageNo = Convert.ToInt32(e.CommandArgument);
                 //Bind grid here

             }
         }
         catch (Exception ex)
         {

         }
     }
 
Share this answer
 
Comments
Member 7695634 21-May-15 11:08am    
Hi Siddartha, thanks for your instant help. This solution I might need while using datalist. But for now, after some research I got http://www.webblogsforyou.com/custom-datapagerrepeater-asp-net-repeater-control-with-datapager-example/ which is exact answer to my question. But still thankful for suggestion you provided. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900