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: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
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
protected void dlPager_ItemCommand(object source, DataListCommandEventArgs e)
{
try
{
if (e.CommandName == "PageNo")
{
pageNo = Convert.ToInt32(e.CommandArgument);
}
}
catch (Exception ex)
{
}
}