分页控件-ASP.NET(AspNetPager)
生活随笔
收集整理的這篇文章主要介紹了
分页控件-ASP.NET(AspNetPager)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?AspNetPager是asp.net中常用的分頁控件,下載AspNetPager.dll,添加引用,在工具欄就可以看到AspNetPager控件:
<div class="oa-el-grid-page"><webdiyer:AspNetPager ID="AspNetPager2" runat="server" CurrentPageButtonClass="current"OnPageChanging="AspNetPager2_PageChanging" FirstPageText="首頁" LastPageText="最后一頁"NextPageText="下一頁" PrevPageText="上一頁" HorizontalAlign="Center" ShowBoxThreshold="10"ShowPageIndexBox="Auto" AlwaysShow="True" PageSize="9"></webdiyer:AspNetPager> `</div> .oa-el-grid-page a, .oa-el-grid-page input[type="submit"] {background-color: #FFFFFF;border-color: #EEEEEE;border-style: solid;border-width: 1px;color: #036CB4;margin: 2px;padding: 2px 5px;text-decoration: none; } .oa-el-grid-page .current {background-color: #036CB4;border-color: #036CB4;border-right: 1px solid #036CB4;border-style: solid;border-width: 1px;color: #FFFFFF;font-weight: bold;margin: 2px;padding: 2px 5px; }?
public void DataLoad(int pidx){string TiaoJian = " 1=1 ";if (txtxfd.Value != "")TiaoJian += " and name like '%" + txtxfd.Value + "%'";AspNetPager2.RecordCount = new BLL.Sys_card_class().GetCount(TiaoJian);//分頁大小、頁碼、排序列,升序{False}/降序(True),條件List<Model.Sys_card_class> LRDate = new BLL.Sys_card_class().GetPageList(AspNetPager2.PageSize, pidx, "id", false, TiaoJian);if (LRDate.Count > 0){int i = 1;foreach (Model.Sys_card_class LR in LRDate){ContentStr += "<tr>";ContentStr += "<td width=\"200px\">" + i.ToString() + "</td>";ContentStr += "<td width=\"310px\">" + LR.id.ToString() + "</td>";ContentStr += "<td width=\"310px\">" + LR.name.ToString() + "</td>";ContentStr += "<td width=\"130px\">";ContentStr += "<a href='Card_class_Edit.aspx?addoredit=edit&id=" + LR.id.ToString() + @"'>編輯</a>";ContentStr += " <a class=\"linkcss\" href=\"#\" οnclick=\"javascript:if(confirm('確定要刪除嗎?')){DeleMenu('" + LR.id.ToString() + "');}\" title=\"刪除\">刪除</a>";ContentStr += " </td>";ContentStr += "</tr>";i++;}}}protected void AspNetPager2_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e){DataLoad(e.NewPageIndex);}?例:
/*樣式一:<webdiyer:AspNetPager CssClass="oa-el-grid-page"*/protected void AspNetPager2_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e){AspNetPager1.CurrentPageIndex = e.NewPageIndex;LoadDataInfo();}protected void AspNetPager1_PageChanged(object src, EventArgs e){LoadDataInfo(); }?下載AspNetPager.dll
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %><webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="9" ShowPageIndexBox="Never"CssClass="pagination" LayoutType="Ul" PagingButtonLayoutType="UnorderedList" PagingButtonSpacing="0" CurrentPageButtonClass="active" OnPageChanged="AspNetPager1_PageChanged" ShowCustomInfoSection="Never"></webdiyer:AspNetPager> /*分頁樣式*/ .liPager {width: 100%;background-color: #F5F5F5;vertical-align: middle;text-align: left;height: 35px;line-height: 35px;display: inline-block; }.liPager li, .liPager a {font-family: 微軟雅黑;font-size: 12px;font-weight: bold;color: white;text-align: center;background-color: #1E71B1;display: inline-block;width: 30px;height: 30px;border-radius: 30px; /* 所有角都使用半徑為5px的圓角,此屬性為CSS3標準屬性 */-moz-border-radius: 30px; /* Mozilla瀏覽器的私有屬性 */-webkit-border-radius: 30px; /* Webkit瀏覽器的私有屬性 */border-radius: 30px 28px 26px 24px; /* 四個半徑值分別是左上角、右上角、右下角和左下角 */}/*======bootstrap風格========*/.pagination {display: inline-block;padding-left: 0;margin: 5px 0;border-radius: 4px;font-size:14px;float: right; }.pagination > li {display: inline;}.pagination > li > a, .pagination > li > span {position: relative;padding: 6px 12px;margin-left: -1px;line-height: 1.42857143;color: #337ab7;text-decoration: none;background-color: #fff;border: 1px solid #ddd;}.pagination > li:first-child > a, .pagination > li:first-child > span {margin-left: 0;border-top-left-radius: 4px;border-bottom-left-radius: 4px;}.pagination > li:last-child > a, .pagination > li:last-child > span {border-top-right-radius: 4px;border-bottom-right-radius: 4px;}.pagination > li > a:focus, .pagination > li > a:hover, .pagination > li > span:focus, .pagination > li > span:hover {color: #23527c;background-color: #eee;border-color: #ddd;}.pagination > .active > a, .pagination > .active > a:focus, .pagination > .active > a:hover, .pagination > .active > span, .pagination > .active > span:focus, .pagination > .active > span:hover {z-index: 2;color: #fff;cursor: default;background-color: #337ab7;border-color: #337ab7;}.pagination > .disabled > a, .pagination > .disabled > a:focus, .pagination > .disabled > a:hover, .pagination > .disabled > span, .pagination > .disabled > span:focus, .pagination > .disabled > span:hover {color: #777;cursor: not-allowed;background-color: #fff;border-color: #ddd;}.pagination-lg > li > a, .pagination-lg > li > span {padding: 10px 16px;font-size: 18px; }.pagination-lg > li:first-child > a, .pagination-lg > li:first-child > span {border-top-left-radius: 6px;border-bottom-left-radius: 6px; }.pagination-lg > li:last-child > a, .pagination-lg > li:last-child > span {border-top-right-radius: 6px;border-bottom-right-radius: 6px; }.pagination-sm > li > a, .pagination-sm > li > span {padding: 5px 10px;font-size: 12px; }.pagination-sm > li:first-child > a, .pagination-sm > li:first-child > span {border-top-left-radius: 3px;border-bottom-left-radius: 3px; }.pagination-sm > li:last-child > a, .pagination-sm > li:last-child > span {border-top-right-radius: 3px;border-bottom-right-radius: 3px; }/*分頁*/ .pagination a[disabled] {color: #777;cursor: not-allowed;background-color: #fff;border-color: #ddd; }.pagination span.active {z-index: 2;color: #fff;cursor: default;background-color: #337ab7;border-color: #337ab7; }?
例2:
/// </summary>/// <param name="ds">DataSet實例</param>/// <param name="datalistname">DataList名稱</param>/// <param name="pagesize">分頁大小</param>public static string GetPageNumjxjdc(DataSet ds, DataList datalistname, int pagesize, string bc){PagedDataSource objPds = new PagedDataSource();objPds.DataSource = ds.Tables[0].DefaultView;objPds.AllowPaging = true;int total = ds.Tables[0].Rows.Count;objPds.PageSize = pagesize;int page;if (HttpContext.Current.Request.QueryString["page"] != null)page = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);elsepage = 1;objPds.CurrentPageIndex = page - 1;datalistname.DataSource = objPds;datalistname.DataBind();int allpage = 0;int next = 0;int pre = 0;int startcount = 0;int endcount = 0;string pagestr = "";string c = bc;if (page < 1) { page = 1; }//計算總頁數(shù)if (pagesize != 0){allpage = (total / pagesize);allpage = ((total % pagesize) != 0 ? allpage + 1 : allpage);allpage = (allpage == 0 ? 1 : allpage);}next = page + 1;pre = page - 1;startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中間頁起始序號//中間頁終止序號endcount = page < 5 ? 10 : page + 5;if (startcount < 1) { startcount = 1; } //為了避免輸出的時候產生負數(shù),設置如果小于1就從序號1開始if (allpage < endcount) { endcount = allpage; } //頁碼+5的可能性就會產生最終輸出序號大于總頁碼,那么就要將其控制在頁碼數(shù)之內pagestr = "共" + allpage + "頁 ";pagestr += page > 1 ? "<a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=1&c=" + c + "\">首頁</a> <a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + pre + "&c=" + c + "\">上一頁</a>" : "首頁 上一頁";//中間頁處理,這個增加時間復雜度,減小空間復雜度//for (int i = startcount; i <= endcount; i++)//{// pagestr += page == i ? " <font color=\"#ff0000\">" + i + "</font>" : " <a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + i + "&c=" + c + "&t=" + t + "\">" + i + "</a>";//}pagestr += page != allpage ? " <a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + next + "&c=" + c + "\">下一頁</a> <a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + allpage + "&c=" + c + "\">末頁</a>" : " 下一頁 末頁";return pagestr; }/*RepeaterTeach.DataSource = ds.Tables[0].DefaultView;RepeaterTeach.DataBind();PageInfo.InnerHtml = GetPageNumjxjdc(ds, RepeaterTeach, 5,"");
*/ <p class="jl_fy" id="PageInfo" runat="server"></p>
?
轉載于:https://www.cnblogs.com/elves/p/3597943.html
總結
以上是生活随笔為你收集整理的分页控件-ASP.NET(AspNetPager)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【在还原SQL Server数据库时发生
- 下一篇: Webbrowers控件的小技巧