<asp:LinkButton ID="Prev" OnClick="Prev_Click" runat="server" Text="Previous" />
<asp:LinkButton ID="Next" OnClick="Next_Click" runat="server" Text="Next" />
then in code behind file -
List<items> itemsList = new List<items>();
MS_items_Controller control = new MS_items_Controller();
itemsList = control.MS_Comments_LoadAllItems(1, 1);
PagedDataSource pages = new PagedDataSource();
pages.AllowPaging = true;
pages.PageSize =10;//size of your page
pages.CurrentPageIndex = CurrentPage;
pages.DataSource = itemsList;
Prev.Enabled = !pages.IsFirstPage;
Next.Enabled = !pages.IsLastPage;
DataList1.DataSource = pages;
DataList1.DataBind();
public int CurrentPage
{
get
{
object o = this.ViewState["_CurrentPage"];
if (o == null)return 0;
else return (int)o;
}
set
{this.ViewState["_CurrentPage"] = value;}
}
protected void Prev_Click(object sender, System.EventArgs e)
{
// int u=Convert.ToInt32(ViewState["CurrentPage2"]);
//CurrentPage -= 1;
CurrentPage -= 1;
// Reload
bindgrid();
}
protected void Next_Click(object sender, System.EventArgs e)
{
CurrentPage += 1;
// Reload
bindgrid();
}