I am using asp.net gridview and for paging I am using repeater control.
But my paging looks like this
What I want is that it should look like this
My code where I am populating my pager is given below
private void PopulatePager(int recordCount, int currentPage)
{
double dblPageCount = (double)((decimal)recordCount / decimal.Parse((1).ToString()));
int pageCount = (int)Math.Ceiling(dblPageCount);
List<ListItem> pages = new List<ListItem>();
if (pageCount > 0)
{
pages.Add(new ListItem("First", "1", currentPage > 1));
for (int i = 1; i <= pageCount; i++)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage));
}
pages.Add(new ListItem("Last", pageCount.ToString(), currentPage < pageCount));
}
// aa.Controls.Add(
System.Web.UI.HtmlControls.HtmlGenericControl g = new System.Web.UI.HtmlControls.HtmlGenericControl();
rptPager.DataSource = pages;
rptPager.DataBind();
}
Any help will be highly appreciated
My repeater control markup is following
<ul class="pagination">
<li>
<asp:LinkButton CssClass="pagination" ID="lnkPage" runat="server" Text = '<%#Eval("Text") %>' CommandArgument = '<%# Eval("Value") %>' Enabled = '<%# Eval("Enabled") %>' OnClick = "Page_Changed"></asp:LinkButton>
</li> </ul>
</ItemTemplate>
</asp:Repeater>
<ul id="aa" runat="server" class="pagination">
You could change the page population to add "..." before and/or after the listed page numbers, and then have logic to only do so if you can't see the first or last page for the range of pages you wish to show. Provided the currentPage and pageCount are accurate, the code below should generate the appropriate page list items for the desired range of pages to show, in this case, 4.
EDIT So your final method becomes: