private void PagingControl1_RecordsPerPageChanged(object sender, EventArgs e) { var query = new URL(this.Request.Url.AbsoluteUri); query.Parameters.SetValue("rpp", PagingControl1.RecordsPerPage.ToString()); query.Parameters.SetValue("po", "1"); this.Response.Redirect(query.ToString()); }
protected override void OnInit(EventArgs e) { base.OnInit(e); if (!this.IsPostBack) { //Populate the page per combo cboPagePer.Items.Add(new ListItem("5" + " " + this.ObjectPlural + " per Page", "5")); cboPagePer.Items.Add(new ListItem("10" + " " + this.ObjectPlural + " per Page", "10")); cboPagePer.Items.Add(new ListItem("20" + " " + this.ObjectPlural + " per Page", "20")); cboPagePer.Items.Add(new ListItem("30" + " " + this.ObjectPlural + " per Page", "30")); cboPagePer.Items.Add(new ListItem("40" + " " + this.ObjectPlural + " per Page", "40")); cboPagePer.Items.Add(new ListItem("50" + " " + this.ObjectPlural + " per Page", "50")); URL url = new URL(this.Request.Url.AbsoluteUri); cboPagePer.SelectedValue = url.RecordsPerPage.ToString(); //cboPagePer.SelectedValue = this.RecordsPerPage.ToString(); this.rpp.Value = cboPagePer.SelectedValue; pnlPagePer.Visible = true; } this.cboPagePer.SelectedIndexChanged += new EventHandler(cboPagePer_SelectedIndexChanged); }
private void PopulateClickBar() { try { var query = new URL(this.Request.Url.AbsoluteUri); pnlGotoPage.Controls.Clear(); HtmlAnchor link = null; if (this.PageIndex > 1) { //Add the 'Previous' page link link = new HtmlAnchor(); link.Attributes.Add("rel", "nofollow"); link.ID = "linkPrevious"; link.InnerText = "<"; pnlGotoPage.Controls.Add(link); query.PageOffset = this.PageIndex - 1; link.HRef = query.ToString(); } Literal literal = new Literal(); literal.Text = " "; pnlGotoPage.Controls.Add(literal); //Try to position the current PageIndex in the middle of the selection int startIndex = this.PageIndex - 5; if (startIndex < 1) startIndex = 1; int endIndex = startIndex + 9; if (endIndex > this.PageCount) endIndex = this.PageCount; if (startIndex == 1 && endIndex <= 1) { pnlGotoContainer.Visible = false; return; } pnlGotoContainer.Visible = true; for (int ii = startIndex; ii <= endIndex; ii++) { link = new HtmlAnchor(); link.Attributes.Add("rel", "nofollow"); link.ID = "linkPage" + ii.ToString(); link.InnerText = ii.ToString(); if (ii == this.PageIndex) link.Attributes.Add("class", "paginggotopageselected"); query.PageOffset = ii; link.HRef = query.ToString(); pnlGotoPage.Controls.Add(link); literal = new Literal(); literal.Text = " "; pnlGotoPage.Controls.Add(literal); } if (this.PageIndex < this.PageCount) { //Add the 'Next' page link link = new HtmlAnchor(); link.Attributes.Add("rel", "nofollow"); link.InnerText = ">"; link.ID = "linkNext"; query.PageOffset = this.PageIndex + 1; link.HRef = query.ToString(); pnlGotoPage.Controls.Add(link); } //If there are many more records then //add a paging mechanism to this paging control int nextIndex = endIndex + 9; nextIndex = nextIndex - (nextIndex % 10); if (nextIndex + 9 <= this.PageCount) { literal = new Literal(); literal.Text = " "; pnlGotoPage.Controls.Add(literal); link = new HtmlAnchor(); link.Attributes.Add("rel", "nofollow"); link.ID = "linkPageN1"; //link.Text = nextIndex.ToString() + "-" + (nextIndex + 9).ToString(); link.InnerText = nextIndex.ToString() + "+"; query.PageOffset = nextIndex; link.HRef = query.ToString(); pnlGotoPage.Controls.Add(link); } //If there are many more records then //add a paging mechanism to this paging control if (nextIndex + 19 <= this.PageCount) { literal = new Literal(); literal.Text = " "; pnlGotoPage.Controls.Add(literal); link = new HtmlAnchor(); link.Attributes.Add("rel", "nofollow"); link.ID = "linkPageN2"; link.InnerText = (nextIndex + 10).ToString() + "+"; query.PageOffset = (nextIndex + 10); if (this.PageIndex == this.PageCount) pnlGotoPage.Controls.Add(link); } } catch (Exception ex) { throw; } }
private void GotoPageClick(object sender, EventArgs e) { URL url = new URL(this.Request.Url.AbsoluteUri); int pageOffset = int.Parse(url.Parameters.GetValue("po", "1")); LinkButton button = (LinkButton)sender; if (button.Text == "<") { pageOffset--; } else if (button.Text == ">") { pageOffset++; } else if (button.Text.IndexOf("+") != -1) { //This is a paging mechanism pageOffset = int.Parse(button.CommandArgument); } else { //The actual page number pageOffset = int.Parse(button.CommandArgument); } url.Parameters.SetValue("po", pageOffset.ToString()); this.Response.Redirect(url.ToString()); }