Custom Paging Web Forms

I am using custom paging for a web site that I am building at the moment there is data spread across 144 pages. Its displaying all 144 page buttons at the bottom and it does not look professional. Is there a way I could reduce the amount of page buttons being displayed and maybe have a button saying next page or something.

Output

enter image description here

Code Behind

 private int PageSize = 4;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.GetCustomersPageWise(1);
            }
        }

        private void GetCustomersPageWise(int pageIndex)
        {
            string constring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constring))
            {
                using (SqlCommand cmd = new SqlCommand("GetCustomersPageWise", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
                    cmd.Parameters.AddWithValue("@PageSize", PageSize);
                    cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4);
                    cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
                    con.Open();
                    IDataReader idr = cmd.ExecuteReader();
                    rptData.DataSource = idr;
                    rptData.DataBind();
                    idr.Close();
                    con.Close();
                    int recordCount = Convert.ToInt32(cmd.Parameters["@RecordCount"].Value);
                    this.PopulatePager(recordCount, pageIndex);
                }
            }
        }

        private void PopulatePager(int recordCount, int currentPage)
        {
            double dblPageCount = (double)((decimal)recordCount / Convert.ToDecimal(PageSize));
            int pageCount = (int)Math.Ceiling(dblPageCount);
            List<ListItem> pages = new List<ListItem>();
            if (pageCount > 0)
            {
                for (int i = 1; i <= pageCount; i++)
                {
                    pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage));
                }
            }
            rptPager.DataSource = pages;
            rptPager.DataBind();
        }

        protected void Page_Changed(object sender, EventArgs e)
        {
            int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
            this.GetCustomersPageWise(pageIndex);
        }

        public override void VerifyRenderingInServerForm(Control control)
        {
            return;
        }

Aspx Page

 <asp:Repeater ID="rptData" runat="server" >
                        <ItemTemplate>
                            <li>
                                <a href="HouseInfo.aspx">
                                    <img src="" alt="img" /></a>
                                <h2>
                                    <asp:Label runat="server" Text='<%# Eval("Name") %>'></asp:Label></h2>
                                <p>
                                    <b>ID: </b>
                                    <asp:Label runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                    <br />
                                    <b>Name of House: </b>
                                    <asp:Label runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                                    <br />
                                    <b>Townland: </b>
                                    <asp:Label runat="server" Text='<%# Eval("Townland") %>'></asp:Label>
                                    <br />
                                    <b>Near: </b>
                                    <asp:Label runat="server" Text='<%# Eval("Near") %>'></asp:Label>
                                    <br />
                                    <b>Status/Public Access: </b>
                                    <asp:Label runat="server" Text='<%# Eval("Status") %>'></asp:Label>
                                    <br />
                                    <b>Date Built: </b>
                                    <asp:Label runat="server" Text='<%# Eval("Built") %>'></asp:Label>
                                </p>
                            </li>
                        </ItemTemplate>
                    </asp:Repeater>
                </ul>
                <asp:Repeater ID="rptPager" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
            style="padding:8px; margin:2px; background:#ac9e94; border:solid 1px #666; font:8pt; color:#594334"
            CssClass='<%# Convert.ToBoolean(Eval("Enabled")) ? "page_enabled" : "page_disabled" %>'
            OnClick="Page_Changed" OnClientClick='<%# !Convert.ToBoolean(Eval("Enabled")) ? "return false;" : "" %>'></asp:LinkButton>
   </ItemTemplate>
</asp:Repeater>


Source: sql

Leave a Reply