I am trying to get the next and prev button on my custom pager. Here is what I have so far and it’s working perfect except it needs next and prev button.
What I have done
PagedDataSource page = new PagedDataSource();
page.AllowCustomPaging = true;
page.AllowPaging = true;
page.DataSource = query;
page.PageSize = 5;
QRep.DataSource = page;
QRep.DataBind();
*Qrep is a asp.net repeater control and *query is a result of linq to sql query.
here is how i create the pager controls and assigned event handlers
private void CreatePagingControl()
{
for (int i = 0; i < (RowCount / 5) + 1; i++)
{
LinkButton lnk = new LinkButton();
lnk.Click += new EventHandler(lbl_Click);
lnk.ID = "lnkPage" + (i + 1).ToString();
lnk.Text = (i + 1).ToString();
plcPaging.Controls.Add(lnk);
Label spacer = new Label();
spacer.Text = " ";
plcPaging.Controls.Add(spacer);
}
}
void lbl_Click(object sender, EventArgs e)
{
LinkButton lnk = sender as LinkButton;
int currentPage = int.Parse(lnk.Text);
int take = currentPage * 5;
int skip = currentPage == 1 ? 0 : take - 5;
FetchData(take, skip);
}
the row count is stored as below
private int RowCount
{
get
{
return (int)ViewState["RowCount"];
}
set
{
ViewState["RowCount"] = value;
}
}
This is working fine , except it only displays page numbers and I want to know how the next and prev controls can be integrated with this. Any help appreicated guys. Thanks in advance.
See the open source pager control for asp.net 3.5 here:
http://www.codeproject.com/KB/custom-controls/ASPNETPagerControl.aspx
Edit
There is also another asp.net pager control with source code here:
http://aspnetpager.codeplex.com/