hi. i am not sure how to solve this issue with paging when search is avalible. it is for a webshop so at first i get products default, then visotors can lets say do a search for brands. but my problem becomes that my paging cause a postback everytime i change page. how is it done to avoid that problem. here is my code i use
protected void Page_Load(object sender, EventArgs e)
{
if ((Request.QueryString["Page"] != null))
{
CurrentPage = int.Parse(Request.QueryString["Page"]);
}
if (!Page.IsPostBack)
{
BindMachinaryDetails(8);
}
}
void BindMachinaryDetails(int catid)//mchar
{
var col = (ICollection)ObjectFactory.GetInstance<IReceiverService>().GetAll();
if (col.Count > 0)
{
var objPds = new PagedDataSource
{
DataSource = col,
AllowPaging = true,
PageSize = 3,
CurrentPageIndex = (CurrentPage - 1)
};
CreatePaging(col.Count);
rpMachDet.DataSource = objPds;
rpMachDet.DataBind();
}
}
public void CreatePaging(int TotalRecords)
{
int TotalPages;
int StartPage;
int VisiblePages;
if (TotalRecords % RecordsPerPage == 0)
{
TotalPages = (TotalRecords / RecordsPerPage); //total pages
}
else
{
TotalPages = (TotalRecords / RecordsPerPage) + 1;
}
//TotalMessages.Text = "Page <b>" + CurrentPage + "</b> of <b>" + TotalPages + "</b>";
//RecordsCount.Text = "<b>" + TotalRecords + "</b> Records";
int i;
int Page;
int.TryParse(Request.QueryString["Page"], out Page);
string NavigationText = "";
if (Request.QueryString["Page"] == null || Page == 1 || Page == 2 || Page == 3)
{
StartPage = 1;
}
else
{
StartPage = Page - 3;
}
if (CurrentPage > 1)
{
var lbnFirst = new LinkButton{ID = "first", };
NavigationText += "<a href=" + Request.ServerVariables["SCRIPT_NAME"] + "?Page=" + (1) + ">First</a>";
NavigationText += "<a href=" + Request.ServerVariables["SCRIPT_NAME"] + "?Page=" + (CurrentPage - 1) + ">< </a> "; //Previous
}
//visa visible pages
if (Page < 3)
{
VisiblePages = 7;
}
else
{
VisiblePages = StartPage + 6;
}
for (i = StartPage; i <= VisiblePages; i++)
{
if (CurrentPage == i)
{
NavigationText += "<b>" + i + "</b> ";
}
else
{
NavigationText += "<a href=" + Request.ServerVariables["SCRIPT_NAME"] + "?Page=" + i + ">" + i + "</a> ";
}
}
if (CurrentPage < TotalPages)
{
NavigationText += "<a href=" + Request.ServerVariables["SCRIPT_NAME"] + "?Page=" + (CurrentPage + 1) + "> ></a> "; //Next
NavigationText += "<a href=" + Request.ServerVariables["SCRIPT_NAME"] + "?Page=" + TotalPages + "> Last</a>";
}
PagingLabel.Text = NavigationText;
}