Introduction
Repeater paging provides the Paging facility in Repeater which was not default given into Repeater control of the ASP.NET.
Background
This includes the Four Linkbuttons, the names of which are First
, Previous
, Next
, Last
respectively and give the paging as per your page requirement like display 5, 10, 15... as you need.
Using the Code
For using this one, you need to integrate this code in your CS file and add this function, then call it wherever you need to display your data.
You have to put four link buttons between your Repeater <separatortemplate>
tag.
public int CurrentPage
{
get
{
object obj = this.ViewState["_CurrentPage"];
if (obj == null)
{
return 0;
}
else
{
return (int)obj;
}
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
public int DisplayRepeter()
{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("projectid", drpprojectlist.SelectedValue);
DataSet ds = cm.SP_Select("SP_StudentSelectByProject", p);
rptstudnet.DataSource = ds;
rptstudnet.DataBind();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 6;
int count = pds.PageCount;
pds.CurrentPageIndex = CurrentPage;
if (pds.Count > 0)
{
lbtnPrev.Visible = true;
lbtnNext.Visible = true;
lbtnFirst.Visible = true;
lbtnLast.Visible = true;
lblStatus.Text = "Page " + Convert.ToString
(CurrentPage + 1) + "of" + Convert.ToString(pds.PageCount);
}
else
{
lbtnPrev.Visible = false;
lbtnNext.Visible = false;
lbtnFirst.Visible = false;
lbtnLast.Visible = false;
}
lbtnPrev.Enabled = !pds.IsFirstPage;
lbtnNext.Enabled = !pds.IsLastPage;
lbtnFirst.Enabled = !pds.IsFirstPage;
lbtnLast.Enabled = !pds.IsLastPage;
rptstudnet.DataSource = pds;
rptstudnet.DataBind();
return count;
}
protected void lbtnPrev_Click(object sender, EventArgs e)
{
CurrentPage -= 1;
DisplayRepeter();
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
DisplayRepeter();
}
protected void lbtnFirst_Click(object sender, EventArgs e)
{
CurrentPage = 0;
DisplayRepeter();
}
protected void lbtnLast_Click(object sender, EventArgs e)
{
CurrentPage = DisplayRepeter() - 1;
DisplayRepeter();
}
Add this link button in your source code of .ASPX page between repeater separatortemplate
.
<li><asp:Button ID="lbtnFirst" runat="server"
class="btn btn-primary" Text="First" onclick="lbtnFirst_Click"
Width="70"></asp:Button></li>
<li><asp:Button ID="lbtnPrev" runat="server"
class="btn btn-primary" Text="Prev"
onclick="lbtnPrev_Click" Width="70"></asp:Button></li>
<li><asp:Button ID="lbtnNext" runat="server"
class="btn btn-primary" Width="70" Text="Next"
onclick="lbtnNext_Click"></asp:Button></li>
<li><asp:Button ID="lbtnLast" runat="server"
class="btn btn-primary" Width="70" Text="Last"
onclick="lbtnLast_Click"></asp:Button></li>
Made changes in the above code as per your requirements like changing the StoreProcedure
, etc.