生活随笔
收集整理的這篇文章主要介紹了
ASPNETPager常用属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<webdiyer:AspNetPager ID="pager" runat="server" class="page" FirstPageText="首頁" LastPageText="尾頁" PageIndexBoxType="DropDownList"
??????????????????? NextPageText="后頁" PageSize="20" PrevPageText="前頁" ShowPageIndexBox="Always" TextAfterPageIndexBox="頁"
??????????????????? TextBeforePageIndexBox="跳轉到: " Width="100%" PagingButtonType="Image" ImagePath="/SysManager/images/"
??????????????????? NumericButtonType="Text" ButtonImageExtension=".jpg" CustomInfoHTML="共%PageCount%頁,當前為第%CurrentPageIndex%頁,每頁%PageSize%條 共 %RecordCount% 條數據"
??????????????????? ShowCustomInfoSection="Right" AlwaysShow="True" MoreButtonType="Text"? OnPageChanged="Pager_PageChanged" >
??????????????? </webdiyer:AspNetPager>
<%--??????????????? <webdiyer:AspNetPager ID="pager" runat="server" class="page" EnableTheming="true"
??????????????????? FirstPageText="首頁" LastPageText="尾頁" NextPageText="后頁" OnPageChanged="Pager_PageChanged"
??????????????????? PageIndexBoxType="DropDownList" PageSize="2" PrevPageText="前頁" ShowPageIndexBox="Always"
??????????????????? TextAfterPageIndexBox="頁" TextBeforePageIndexBox="跳轉到: " Width="100%" NumericButtonType="Text"
??????????????????? CustomInfoHTML="共%PageCount%頁,當前為第%CurrentPageIndex%頁,每頁%PageSize%條 共%RecordCount%條數據" ShowCustomInfoSection="Right"
??????????????????? AlwaysShow="True">
??????????????? </webdiyer:AspNetPager>--%>
以下是一個完整的示例: <webdiyer:aspnetpager id="AspNetPager1" runat="server"? ???????alwaysshow="True" ???????PageSize="5"? ???????custominfosectionwidth="20%"? ???????custominfotextalign="Right"? ???????firstpagetext="第一頁" ???????horizontalalign="Left"? ???????lastpagetext="末一頁"? ???????navigationbuttontype="Image"?? ???????nextpagetext="后一頁" ???????pageindexboxtype="TextBox" ???????pagingbuttonspacing="8px" ???????prevpagetext="前一頁"? ???????showcustominfosection="Right"? ???????showpageindexbox="Always"? ???????textafterpageindexbox="頁"? ???????UrlPaging="true"? ???????textbeforepageindexbox="跳到第" ???????width="97%"? ???????onpagechanged="AspNetPager1_PageChanged"> </webdiyer:aspnetpager> alwaysshow:總是顯示分頁控件; PageSize:指定每頁顯示的記錄數; custominfosectionwidth:用戶自定義信息區的寬度; custominfotextalign:用戶自定義信息區的對齊方式; firstpagetext:第一頁按鈕上顯示的文本; horizontalalign:內容水平對齊方式; lastpagetext:最后頁按鈕上顯示的文本; navigationbuttontype:第一頁、下一頁、最后一頁按鈕的類型; nextpagetext:下一頁按鈕上顯示的文本; pageindexboxtype:指示頁索引框的顯示類型:有TextBOX和dropdownlist兩種; pagingbuttonspacing:導航頁按鈕的間距; prevpagetext:上一頁按鈕的顯示的文本; showcustominfosection:顯示當前頁和總頁信息,默認為不顯示,值為LEFT時將顯示在頁索引前,為right時顯示在頁索引后; showpageindexbox:指定頁索引文本框或下拉框的顯示方式; textafterpageindexbox:指定頁索引文本框或下拉框后的文本; UrlPaging:是夠使用URL傳遞分頁的方式來分頁; textbeforepageindexbox:指定頁索引文本框或下拉框前面顯示的文本; width:該控件的寬度; CustomInfoHTML:指定要顯示在用戶自定義信息區的用戶自定義HTML信息文本 ??? using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page? { ????protected void Page_Load(object sender, EventArgs e) ????{ ????????Bind(); ????} ????private void Bind() ????{ ????????int pageindex = 1; ????????int pagenum = AspNetPager1.PageSize; ????????if (Request["page"] != null) ????????{ ????????????pageindex =Convert.ToInt32(Request["page"]); ????????} ????????DataSet ds = new DataSet(); ????????SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString ()); ????????SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString()); ????????SqlDataAdapter sda = new SqlDataAdapter("select top (@pagenum) * from pagetest where id not in (select top? (@pagenum*(@pageindex-1)) id from pagetest)", con); ????????sda.SelectCommand.Parameters.AddWithValue("pagenum",pagenum); ????????sda.SelectCommand.Parameters.AddWithValue("pageindex",pageindex); ????????sda.Fill(ds); ????????SqlCommand cmd = new SqlCommand("select count(*) from pagetest", con1); ????????con1.Open(); ????????AspNetPager1.RecordCount =Convert.ToInt32(cmd.ExecuteScalar()); ????????con.Close(); ????????AspNetPager1.CustomInfoHTML = "共" + AspNetPager1.RecordCount + "條記錄????? " + AspNetPager1.CurrentPageIndex + "/" + AspNetPager1.PageCount; ????????GridView1.DataSource = ds.Tables[0].DefaultView; ????????GridView1.DataBind(); ????} ????protected void AspNetPager1_PageChanged(object sender, EventArgs e) ????{ ????????Bind(); ????} } 深入分析CurrentPageIndex、RecordCount、 PageCount、 PageSize: ?? pagecount: ?? public int PageCount { ????get ????{ ????????if (this.RecordCount == 0) ????????{ ????????????return 1; ????????} ????????return (int) Math.Ceiling((double) (((double) this.RecordCount) / ((double) this.PageSize))); ????} } recordcount: ?? public int RecordCount { ????get ????{ ????????if (this.cloneFrom != null) ????????{ ????????????return this.cloneFrom.RecordCount; ????????} ????????object obj2 = this.ViewState["Recordcount"]; ????????if (obj2 != null) ????????{ ????????????return (int) obj2; ????????} ????????return 0; ????} ????set ????{ ????????this.ViewState["Recordcount"] = value; ????} } CurrentPageIndex: ?? public int CurrentPageIndex { ????get ????{ ????????if (this.cloneFrom != null) ????????{ ????????????return this.cloneFrom.CurrentPageIndex; ????????} ????????object obj2 = this.ViewState["CurrentPageIndex"]; ????????int num = (obj2 == null) ? 1 : ((int) obj2); ????????if ((num > this.PageCount) && (this.PageCount > 0)) ????????{ ????????????return this.PageCount; ????????} ????????if (num < 1) ????????{ ????????????return 1; ????????} ????????return num; ????} ????set ????{ ????????int pageCount = value; ????????if (pageCount < 1) ????????{ ????????????pageCount = 1; ????????} ????????else if (pageCount > this.PageCount) ????????{ ????????????pageCount = this.PageCount; ????????} ????????this.ViewState["CurrentPageIndex"] = pageCount; ????} } PageSize: ?? public int PageSize { ????get ????{ ????????int num; ????????if ((!string.IsNullOrEmpty(this.UrlPageSizeName) && !base.DesignMode) && (int.TryParse(this.Page.Request.QueryString[this.UrlPageSizeName], out num) && (num > 0))) ????????{ ????????????return num; ????????} ????????if (this.cloneFrom != null) ????????{ ????????????return this.cloneFrom.PageSize; ????????} ????????object obj2 = this.ViewState["PageSize"]; ????????if (obj2 != null) ????????{ ????????????return (int) obj2; ????????} ????????return 10; ????} ????set ????{ ????????this.ViewState["PageSize"] = value; ????} }
總結
以上是生活随笔為你收集整理的ASPNETPager常用属性的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。