... ...
<!-- 企業新聞列表開始,圖尺寸550*310,如果沒圖,則在li上加on --> <div class="common-box new-box"> <!-- 列表1開始 --> <ul class="list1"> </ul> <!-- 列表1結束 --> <!-- 翻頁開始 --> <div class="page-box"> </div> <!-- 翻頁結束 --> </div> <!-- 企業新聞列表結束 -->
<script type="text/javascript"> var PageValue = 1; var pageIndex = 1; // 索引頁 var pageCount = '<%=pageCount%>'; // 每頁數量 var PageIndexCount = 0; //分頁總數 var pagecount = 0; locationChange(1); // 載入數據 function locationChange(index) { pageIndex = index; $.ajax({ type: "post", dataType: "json", url: "/ashx/NewList.ashx", data: { pageSize: pageCount, page: index, kind: "<%=curKind%>"}, success: function(data) { var table = data.data.Rows; pagecount = data.PageCount; var PageOutStr = data.PageOutStr; var content = ""; if (table.length > 0) { for (var i = 0; i < table.length; i++) { var row = table[i]; if (row["c_picurl1"] != null && row["c_picurl1"] != "") { content += "<li>"; content += "<!-- 左側圖片開始 -->"; content += "<div class=\"left img-box\">"; content += "<a href=\"" + row["c_linkurl"] + "\">"; content += "<img src=\"" + row["c_picurl1"] + "\">"; content += "</a>"; content += "</div>"; content += "<!-- 左側圖片結束 -->"; } else { content += "<li class='on'>"; } content += "<!-- 右側內容開始 -->"; content += "<div class=\"cont\">"; content += "<div class=\"name\"><a href=\"" + row["c_linkurl"] + "\" title='" + row["c_info_title"] + "'>" + row["c_info_title"] + "</a></div>"; content += "<div class=\"doc\">" + row["beizhu1"] + "</div>"; content += "<div class=\"time\">"; content += "<img src=\"images/time-icon.png\"><span>" + row["d_list_date"] + "</span>"; content += "</div>"; content += "<div class=\"more\">"; content += "<a href=\"" + row["c_linkurl"] + "\">瞭解詳情<em><img src=\"images/more-icon1.png\" class=\"i1\"><img src=\"images/more-icon1.png\" class=\"i2\"></em></a>"; content += "</div>"; content += "</div>"; content += "<!-- 右側內容結束 -->"; content += "</li>"; } } else { content += "<div style=\"color:gray; padding-top:10px;\">暫無相關內容......</div>"; } $(".list1").html(content); $(".page-box").show(); $(".page-box").html(PageOutStr); }, error: function(data) { } }); } </script>
<%@ WebHandler Language="C#" Class="NewList" %> using System; using System.Web; using Solucky; using Maticsoft.Common; using MT.Business; using System.Data; public class NewList : IHttpHandler { private int PageCount; private string PageOutStr; int kind; string Order = ""; string tableName = ""; string sqlwhere = ""; string searchStr = ""; public void ProcessRequest (HttpContext context) { try { context.Response.ContentType = "application/json"; kind = GetContent.CheckInt(PageValidate.SqlTextClear(context.Request.Form["kind"])); int pageSize = GetContent.CheckInt(PageValidate.SqlTextClear(context.Request.Form["pageSize"])); int page = GetContent.CheckInt(PageValidate.SqlTextClear(context.Request.Form["page"])); Order = "n_is_head asc, n_order desc,d_list_date desc,id desc"; tableName = "B_NEWS"; sqlwhere = GetWhere(); searchStr = "id,c_info_title,a2,a3,g_id,c_picurl1,beizhu1,CONVERT(varchar(100), d_list_date, 23) as d_list_date,c_kind_num,'1' c_linkurl,'1' date1,'1' date2"; PagerRowNumber2 pagerRowNumber = new PagerRowNumber2(0, pageSize, page, sqlwhere, searchStr, Order, tableName, ""); // 數據總條數 //int count = pagerRowNumber.getDataCount(); PagerRowNumber2.PagerHtml pagerHtml = pagerRowNumber.Result; //修正當前頁,如果傳入一個非法的數值,能自動定位到第一頁或最後一頁 page = pagerHtml.getPageIndex(); PageCount = pagerHtml.getPageCount(); PageOutStr =pagerHtml.getFirst()+ pagerHtml.getPre() + pagerHtml.getPagerStr() + pagerHtml.getNext()+pagerHtml.getLast(); Json json = new Json(); DataTable dt = pagerRowNumber.DataTable; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["c_linkurl"] =KindUtils.GetDetailUrl(dt.Rows[i]["c_kind_num"].ToString())+"&id="+ dt.Rows[i]["id"].ToString(); dt.Rows[i]["d_list_date"] = Convert.ToDateTime(dt.Rows[i]["d_list_date"]+"").ToString("yyyy.MM.dd"); dt.Rows[i]["beizhu1"] = dt.Rows[i]["beizhu1"]+""; if (!string.IsNullOrEmpty(dt.Rows[i]["c_picurl1"].ToString())) { dt.Rows[i]["c_picurl1"] = Constant.UploadDir + "s/" + dt.Rows[i]["g_id"] + "/" + dt.Rows[i]["c_picurl1"]; } } } string dtdata = json.Convert2Json(dt); string result = "{\"data\":" + dtdata + ",\"page\":" + page + ",\"PageCount\":" + PageCount; if (PageCount > 1) { result += ",\"PageOutStr\":" + GetContent.WriteStrForJson(PageOutStr); } else { result += ",\"PageOutStr\":\"\""; } result += "}"; context.Response.Write(result); } catch (System.Exception ex) { throw ex; } } /// <summary> /// 獲取where語句 /// </summary> /// <returns></returns> private string GetWhere() { string sqlwhere = "where id>0 and c_kind_num='" + kind + "' and n_is_active=1"; return sqlwhere; } public bool IsReusable { get { return false; } } }
using System; /// <summary> /// 新聞 /// 添加人:cz /// 時間:20171127 /// </summary> public partial class news : BasePage { protected int pageSize = 1; protected int strPageIndex = 0; //頁面索引 protected void Page_Load(object sender, EventArgs e) { try { } catch (Exception ex) { throw ex; } } }