public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
public int PageIndex
{
get
{
return (ViewState["PageIndex"] == null ? 0 : Convert.ToInt32(ViewState["PageIndex"]));
}
set
{
ViewState["PageIndex"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindRepeater();
}
}
private void BindRepeater()
{
IshanDataset.OpeningPostRow[] list;
IshanDataset.OpeningPostDataTable dt = OpeningPost.GetAllOpeningPosts();
list = dt.OrderBy(p => p.SortOrder).ToArray();
PagedDataSource pgitems = new PagedDataSource();
pgitems.DataSource = list;
pgitems.AllowPaging = true;
pgitems.PageSize = 10;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
repOpeningPosts.DataSource = pgitems;
repOpeningPosts.DataBind();
}
protected void rptPages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
int pageno = Convert.ToInt32(e.Item.DataItem);
LinkButton lkbPage = e.Item.FindControl("btnPage") as LinkButton;
lkbPage.PostBackUrl = Request.RawUrl;
lkbPage.CommandArgument = pageno.ToString();
lkbPage.Text = (pageno).ToString();
if (PageIndex == pageno)
{
lkbPage.CssClass = "lnkselect";
}
}
}
protected void btnPage_Click(object sender, EventArgs e)
{
LinkButton lkbPage = sender as LinkButton;
int pageno = Convert.ToInt32(lkbPage.CommandArgument);
PageIndex = pageno;
PageNumber = pageno - 1;
BindRepeater();
}
<asp:Repeater ID="repOpeningPosts" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li style="width: 100%; float: left; padding-top: 15px;">
<div style="float: left;">
<h5>
<a href="#" style="color: #4b4b4b; text-decoration: underline;">
<%# Eval("PostTitle")%></a>
</h5>
</div>
<div style="float: right; width: 500px; padding-left: 15px; font-size: 11px; text-align: right;
text-decoration: underline; font-weight: bold;">
<i>
<%# DataBinder.Eval(Container.DataItem, "ClosingDate", "{0:dd MMMM yyyy}") %></i>
</div>
<div style="clear: both; padding-top: 10px;">
<p style="color: #151515; font-size: 12px;">
<%# Common.Strip(Eval("Description").ToString()).ToString().Length > 150 ? Common.Strip(Eval("Description").ToString()).ToString().Substring(0, 150) + " ..." :
Common.Strip(Eval("Description").ToString()).ToString()
%></p>
<a href="#" style="float: right; color: #bd384d; font-size: 12px;">Read More...</a>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rptPages" runat="server" OnItemDataBound="rptPages_ItemDataBound">
<HeaderTemplate>
<div style="float: left;">
<b>Page:</b>
</div>
<div style="float: left;">
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" runat="server" OnClick="btnPage_Click" CssClass="lnkpaging">
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
public int PageIndex
{
get
{
return (ViewState["PageIndex"] == null ? 0 : Convert.ToInt32(ViewState["PageIndex"]));
}
set
{
ViewState["PageIndex"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindRepeater();
}
}
private void BindRepeater()
{
IshanDataset.OpeningPostRow[] list;
IshanDataset.OpeningPostDataTable dt = OpeningPost.GetAllOpeningPosts();
list = dt.OrderBy(p => p.SortOrder).ToArray();
PagedDataSource pgitems = new PagedDataSource();
pgitems.DataSource = list;
pgitems.AllowPaging = true;
pgitems.PageSize = 10;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
repOpeningPosts.DataSource = pgitems;
repOpeningPosts.DataBind();
}
protected void rptPages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
int pageno = Convert.ToInt32(e.Item.DataItem);
LinkButton lkbPage = e.Item.FindControl("btnPage") as LinkButton;
lkbPage.PostBackUrl = Request.RawUrl;
lkbPage.CommandArgument = pageno.ToString();
lkbPage.Text = (pageno).ToString();
if (PageIndex == pageno)
{
lkbPage.CssClass = "lnkselect";
}
}
}
protected void btnPage_Click(object sender, EventArgs e)
{
LinkButton lkbPage = sender as LinkButton;
int pageno = Convert.ToInt32(lkbPage.CommandArgument);
PageIndex = pageno;
PageNumber = pageno - 1;
BindRepeater();
}
<asp:Repeater ID="repOpeningPosts" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li style="width: 100%; float: left; padding-top: 15px;">
<div style="float: left;">
<h5>
<a href="#" style="color: #4b4b4b; text-decoration: underline;">
<%# Eval("PostTitle")%></a>
</h5>
</div>
<div style="float: right; width: 500px; padding-left: 15px; font-size: 11px; text-align: right;
text-decoration: underline; font-weight: bold;">
<i>
<%# DataBinder.Eval(Container.DataItem, "ClosingDate", "{0:dd MMMM yyyy}") %></i>
</div>
<div style="clear: both; padding-top: 10px;">
<p style="color: #151515; font-size: 12px;">
<%# Common.Strip(Eval("Description").ToString()).ToString().Length > 150 ? Common.Strip(Eval("Description").ToString()).ToString().Substring(0, 150) + " ..." :
Common.Strip(Eval("Description").ToString()).ToString()
%></p>
<a href="#" style="float: right; color: #bd384d; font-size: 12px;">Read More...</a>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rptPages" runat="server" OnItemDataBound="rptPages_ItemDataBound">
<HeaderTemplate>
<div style="float: left;">
<b>Page:</b>
</div>
<div style="float: left;">
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" runat="server" OnClick="btnPage_Click" CssClass="lnkpaging">
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
No comments:
Post a Comment