I have created sample. Refer the below code.
You need to change the below css. I have modified the below css.
.button
{
padding-right: 5px;
color: #ababab;
height: 27px;
min-width: 51px;
line-height: 30px;
display: table-cell;
text-align: center;
text-decoration: none;
vertical-align: middle;
font: 14px behtop_Yekan;
background: url(Chrysanthemum.jpg) no-repeat;
}
.button1
{
color: #fb00c2;
padding-right: 5px;
text-decoration: none;
}
#divre1
{
display: table;
margin: 0 auto;
direction: rtl;
float: left;
}
#divre
{
float: left; /*background: url(Chrysanthemum.jpg) no-repeat;*/
width: 800px;
height: 44px;
padding-left: 50px;
}
HTML
<div>
<asp:DataList ID="dlCustomers" runat="server" RepeatDirection="Horizontal" RepeatColumns="3">
<ItemTemplate>
<table cellpadding="2" cellspacing="0" class="Item">
<tr>
<td class="header">
<b><u>
<%# Eval("ContactName") %></u></b>
</td>
</tr>
<tr>
<td class="body">
<b>City: </b>
<%# Eval("City") %><br />
<b>Postal Code: </b>
<%# Eval("PostalCode") %><br />
<b>Country: </b>
<%# Eval("Country")%><br />
<b>Phone: </b>
<%# Eval("Phone")%><br />
<b>Fax: </b>
<%# Eval("Fax")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
<div id="divre">
<div id="divre1">
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass='<%# Eval("CssClass") %>' OnClick="Page_Changed" OnClientClick='<%# !Convert.ToBoolean(Eval("Enabled")) ? "return false;" : "" %>'></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<asp:Repeater ID="rptPager2" runat="server" Visible="false">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass='<%# Eval("CssClass") %>' OnClientClick='<%# !Convert.ToBoolean(Eval("Enabled")) ? "return false;" : "" %>'></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.Item
{
height: 150px;
width: 180px;
margin: 5px;
}
.Item, .Item td, .Item td
{
border: 1px solid #ccc;
}
.Item .header
{
background-color: #F7F7F7 !important;
color: Black;
font-size: 10pt;
line-height: 200%;
}
.page_enabled, .page_disabled
{
display: inline-block;
height: 25px;
min-width: 25px;
line-height: 25px;
text-align: center;
text-decoration: none;
border: 1px solid #ccc;
}
.page_enabled
{
background-color: #eee;
color: #000;
}
.page_disabled
{
background-color: #6C6C6C;
color: #fff !important;
}
.pager
{
background: url(../image/Main/PageN.png) no-repeat;
color: #ababab;
height: 27px;
min-width: 27px;
line-height: 30px;
text-align: center;
text-decoration: none;
font: 13px behtop_Yekan;
margin-top: 1px;
vertical-align: middle;
display: table-cell;
}
.active_pager
{
color: white;
height: 27px;
min-width: 27px;
line-height: 20px;
text-align: center;
text-decoration: none;
font: bold 13px behtop_Yekan;
background: url(../image/Main/PageNA.png) no-repeat;
vertical-align: middle;
display: table-cell;
}
.button
{
padding-right: 5px;
color: #ababab;
height: 27px;
min-width: 51px;
line-height: 30px;
display: table-cell;
text-align: center;
text-decoration: none;
vertical-align: middle;
font: 14px behtop_Yekan;
background: url(Chrysanthemum.jpg) no-repeat;
}
.button1
{
color: #fb00c2;
padding-right: 5px;
text-decoration: none;
}
#divre1
{
display: table;
margin: 0 auto;
direction: rtl;
float: left;
}
#divre
{
float: left; /*background: url(Chrysanthemum.jpg) no-repeat;*/
width: 800px;
height: 44px;
padding-left: 50px;
}
</style>
Code
private int PageSize = 6;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetCustomersPageWise(1);
}
}
private void GetCustomersPageWise(int pageIndex)
{
string constring = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("GetCustomersPageWiseDataList", 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();
dlCustomers.DataSource = idr;
dlCustomers.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 / (decimal)PageSize);
int pageCount = (int)Math.Ceiling(dblPageCount);
List<PagerPage> pages = new List<PagerPage>();
if (pageCount > 0)
{
pages.Add(new PagerPage("   اولین   ", "1", currentPage > 1, "button"));
if (pageCount < 4)
{
for (int i = 1; i <= pageCount; i++)
{
pages.Add(new PagerPage(i.ToString(), i.ToString(), i != currentPage));
}
}
else if (currentPage < 4)
{
for (int i = 1; i <= 4; i++)
{
pages.Add(new PagerPage(i.ToString(), i.ToString(), i != currentPage));
}
pages.Add(new PagerPage("...", (currentPage).ToString(), false, "button1"));
}
else if (currentPage > pageCount - 4)
{
pages.Add(new PagerPage("...", (currentPage).ToString(), false, "button1"));
for (int i = currentPage - 1; i <= pageCount; i++)
{
pages.Add(new PagerPage(i.ToString(), i.ToString(), i != currentPage));
}
}
else
{
pages.Add(new PagerPage("...", (currentPage).ToString(), false));
for (int i = currentPage - 2; i <= currentPage + 2; i++)
{
pages.Add(new PagerPage(i.ToString(), i.ToString(), i != currentPage));
}
pages.Add(new PagerPage("...", (currentPage).ToString(), false));
}
pages.Add(new PagerPage("   آخرین   ", pageCount.ToString(), currentPage < pageCount, "button"));
}
rptPager.DataSource = pages;
rptPager.DataBind();
rptPager2.DataSource = pages;
rptPager2.DataBind();
}
protected void Page_Changed(object sender, EventArgs e)
{
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
this.GetCustomersPageWise(pageIndex);
}
public class PagerPage
{
public PagerPage(string text, string value)
{
Text = text;
Value = value;
}
public PagerPage(string text, string value, bool enabled)
{
Enabled = enabled;
Text = text;
Value = value;
CssClass = enabled ? "pager" : "active_pager";
}
public PagerPage(string text, string value, string cssClass)
{
CssClass = cssClass;
Text = text;
Value = value;
}
public PagerPage(string text, string value, bool enabled, string cssClass)
{
Enabled = enabled;
CssClass = cssClass;
Text = text;
Value = value;
}
public bool Enabled { get; set; }
public bool Selected { get; set; }
public string Text { get; set; }
public string Value { get; set; }
public string CssClass { get; set; }
}
Screenshot