分页显示新闻列表源代码

代码.cs中 using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using yestem.webplug.Utility; using yestem.webplug.DBTools; using yestem.webplug.Model; using yestem.webplug.SQLServerDAL; using yestem.webplug.BLL; using System.Text; using yestem.webplug.web.components.catalog_001.BLL; using yestem.webplug.web.components.catalog_001.Model; public partial class templates_second_index : System.Web.UI.Page { public StringBuilder newsLists; protected void Page_Load(object sender, EventArgs e) { DBConnection DBconn = new DBConnection(); string nodeid = Universal.ConvertNullToEmpty(Request.QueryString["nodeid"]); string page = Universal.ConvertNullToEmpty(Request.QueryString["page"]); string contentid = Universal.ConvertNullToEmpty(Request.QueryString["contentid"]); if (page != null && page == "ContentPage" && contentid != null && contentid != "") { Response.Redirect(Request.RawUrl.Replace("/index.aspx", "/content.aspx")); } int numNodeid = 0; if ((!string.IsNullOrEmpty(nodeid)) && int.TryParse(nodeid, out numNodeid)) { //Node nodeInfo = new NodeBLL().GetModel(DBconn, numNodeid); NodeComponentBLL nodeComBll = new NodeComponentBLL(); //int nodeComID = nodeComBll.GetComponentIDOfNode(DBconn, numNodeid); //NodeComponent nodeCom = nodeComBll.GetModel(DBconn, nodeComID); int productID = nodeComBll.GetProductIDOfNode(DBconn, numNodeid); if (productID != null && productID > 0 && productID == 76 && Request.RawUrl.Contains("&page=ContentPage&") == false) { this.newsList.Visible = true; this.nPage.Visible = true; string pagesize = Request.QueryString["pagesize"]; if (string.IsNullOrEmpty(pagesize)) { pagesize = "1"; } string pagenum = Request.QueryString["pagenum"]; if (string.IsNullOrEmpty(pagenum)) { pagenum = "15"; } newsLists = new StringBuilder(); string sql = "select * from catalog_001_item where notdisplay=0 and nodeid='" + nodeid.Replace("'", "''") + "'"; PageApp app = new PageApp(int.Parse(pagesize), int.Parse(pagenum), sql, "addtime desc,ordernum desc,itemid desc"); //this.NewsList.DataSource = app.Ds; //this.NewsList.DataBind();&pagesize=2&pagenum=10 //yestem.webplug.web.components.catalog_001.Utility.PageApp app = new yestem.webplug.web.components.catalog_001.Utility.PageApp(int.Parse(pagesize), int.Parse(pagenum), sql, "addtime desc,ordernum desc,itemid desc"); DataSet ds = app.Ds; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if ((i + 1) % 2 == 1) { //newsLists.Append(" " + Universal.MaxLengthText(ds.Tables[0].Rows[i]["title"].ToString(), 40) + " [" + getDate(ds.Tables[0].Rows[i]["addtime"].ToString()) + "]"); newsLists.Append(" " + Universal.MaxLengthText(ds.Tables[0].Rows[i]["title"].ToString(), 38) + " [" + getDate(ds.Tables[0].Rows[i]["addtime"].ToString()) + "]"); } else { newsLists.Append(" " + Universal.MaxLengthText(ds.Tables[0].Rows[i]["title"].ToString(), 38) + " [" + getDate(ds.Tables[0].Rows[i]["addtime"].ToString()) + "]"); } }//<%-- 上一页 1 2 3 4 5 下一页 尾页--%> string sqlPage = "select count(*) as countNum from catalog_001_item where notdisplay=0 and nodeid='" + nodeid.Replace("'", "''") + "'"; DataSet ds1 = SqlHelper.ExecuteDataset(DBconn.conn, CommandType.Text, sqlPage); int countNum = 0; if (ds1 != null && ds1.Tables[0].Rows.Count > 0) { countNum = int.Parse(ds1.Tables[0].Rows[0]["countNum"].ToString()); } if (countNum > 0) { string pageUrl = System.Configuration.ConfigurationManager.AppSettings["WebSiteDomain"] + "/templates/news/index.aspx?nodeid=" + numNodeid; StringBuilder pageList = new StringBuilder(); int pageCount = 0; if (int.Parse(pagenum) < 1) { pagenum = "15"; } if (countNum % int.Parse(pagenum) == 0) { pageCount = countNum / int.Parse(pagenum); } else { pageCount = (countNum / int.Parse(pagenum)) + 1; } if (pageCount > 0) { if (int.Parse(pagesize) > pageCount) { pagesize = pageCount + ""; } if (int.Parse(pagesize) < 1) { pagesize = "1"; } if (int.Parse(pagesize) == 1) { pageList.Append(" "); } else {// pageList.Append(" "); } if (pageCount > 5) { if (int.Parse(pagesize) < pageCount) { if (int.Parse(pagesize) > 4) { for (int i = int.Parse(pagesize) - 3; i < int.Parse(pagesize) + 2; i++) { if (i == int.Parse(pagesize)) { pageList.Append(" " + i + ""); } else { pageList.Append(" " + i + ""); } } } else { for (int i = 1; i < 6; i++) { if (i == int.Parse(pagesize)) { pageList.Append(" " + i + ""); } else { pageList.Append(" " + i + ""); } } } } else { if (int.Parse(pagesize) > 4) { for (int i = int.Parse(pagesize) - 4; i < int.Parse(pagesize) + 1; i++) { if (i == int.Parse(pagesize)) { pageList.Append(" " + i + ""); } else { pageList.Append(" " + i + ""); } } } else { for (int i = 1; i < int.Parse(pagesize) + 1; i++) { if (i == int.Parse(pagesize)) { pageList.Append(" " + i + ""); } else { pageList.Append(" " + i + ""); } } } } } else { for (int i = 1; i < pageCount + 1; i++) { if (i == int.Parse(pagesize)) { pageList.Append(" " + i + ""); } else { pageList.Append(" " + i + ""); } } } if (int.Parse(pagesize) == pageCount) { pageList.Append(" "); //pageList.Append(" 尾页"); } else { pageList.Append(" "); //pageList.Append(" 尾页"); } if (pageCount > 1) { this.pages.Text = pageList.ToString(); } } } } else { this.newsList.Visible = false; this.nPage.Visible = false; } } else { this.newsList.Visible = false; this.nPage.Visible = false; } } public string getDate(string date) { try { DateTime d = DateTime.Parse(date); return d.ToString("yyyy-MM-dd"); } catch { return ""; } } public string getContentUrl(string nodeid, string ItemID, string ForceUrl) { if (ForceUrl == "#") { return "#"; } string url = ""; if (ForceUrl == null || ForceUrl == "") { url = System.Configuration.ConfigurationManager.AppSettings["WebSiteDomain"] + "/templates/T_second/index.aspx?nodeid=" + nodeid + "&page=ContentPage&contentid=" + ItemID; } else if (ForceUrl.StartsWith("/")) { url = System.Configuration.ConfigurationManager.AppSettings["WebSiteDomain"] + ForceUrl; } else { url = ForceUrl.StartsWith("http://") ? ForceUrl : "http://" + ForceUrl; } return url.Replace("/T_second/index.aspx", "/T_second/content.aspx"); } public string GetContentUrl(string ForceUrl, string ItemID) { /*string accessorypath = ""; try { string page = "ContentPage"; accessorypath = Universal.GetHtmlSourceCode(System.Configuration.ConfigurationManager.AppSettings["LocalWebSite"] + "/include/getdata/getdata.aspx?type=getaccessorypath&nodeid=" + nodeid + "&acctype=" + page + "&time=" + DateTime.Now.Millisecond); } catch { } if (accessorypath == "" || ForceUrl == "#")*/ if (ForceUrl == "#") { return "return false;"; } string url = ""; if (ForceUrl == null || ForceUrl == "") { url = "window.open(locationAddParam(locationAddParam(locationDelParam(locationDelParam(locationDelParam('','pagesize'),'pagenum'),'condition'),'page','ContentPage'),'contentid','" + ItemID + "'),'','');return false;"; } else { url = "window.open(locationAddParam(locationDelParam('','condition'),'forceurl','" + Server.UrlEncode((ForceUrl.StartsWith("http://") ? ForceUrl : "http://" + ForceUrl)) + "'),'','');return false;"; } return url; } } 前台.aspx中
  • <%=newsLists.ToString()%>

你可能感兴趣的:(分页显示新闻列表源代码)