`
白玉水堂
  • 浏览: 14600 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

上一条、下一条记录

 
阅读更多
前台页面:
<span><font>上一条:</font><% if (preRecordId == -1)
           { %>
        <%=preRecordtitle%>
         <%}
           else
           { %>
        <a href='Notice.aspx?noticeid=<%=preRecordId %>' title='<%=pretitle %>'><%=preRecordtitle%></a>  <%} %>         
         &nbsp;<font>下一条:</font>
        <% if (nextRecordId == -1)
           { %>
        <%=nextRecordtitle%>
         <%}
           else
           { %><a href="Notice.aspx?noticeid=<%=nextRecordId %>" title='<%=nexttitle %>'><%=nextRecordtitle %> </a>   <%} %> </span>


后台页面:
DataTable pdt = new DataTable();
    DataTable ndt = new DataTable();
    NewsManager nm = new NewsManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        //第一次加载页面时
        if (!Page.IsPostBack)
        {
            //每条新闻的访问量+1,并修改回数据库
            string noticeid = Request.QueryString["noticeid"];
           
            //获取上一条记录的通知所有字段
            pdt = nm.SelectAllNoticePreRecordId(noticeid);

            //获取下一条记录的通知所有字段    
            ndt = nm.SelectAllNoticeNextRecorId(noticeid);
        }
    }
    //获取上一条记录ID
    public int preRecordId
    {
        get
        {
            if (pdt == null)
            {
                return -1;
            }
            else
            {
                return Convert.ToInt32(pdt.Rows[0]["id"].ToString());
            }
        }
    }
    //获取下一条记录ID
    public int nextRecordId
    {
        get
        {
            if (ndt == null)
            {
                return -1;
            }
            else
            {
                return Convert.ToInt32(ndt.Rows[0]["id"].ToString());
            }
        }
    }
    //获取上一条记录的标题
    public string preRecordtitle
    {
        get
        {
            if (pdt == null)
            {
                return "没有通知了";
            }
            else
            {
                return StringTruncat(pdt.Rows[0]["title"].ToString(), 10, "…"); 
            }           
        }
    }
    public string pretitle
    {
        get
        {
            if (pdt == null)
            {
                return "没有通知了";
            }
            else
            {
                return pdt.Rows[0]["title"].ToString(); 
            }           
        }
    }
    //获取下一条记录的标题
    public string nextRecordtitle
    {
        get
        {
            if (ndt == null)
            {
                return "没有通知了";
            }
            else
            {
                return StringTruncat(ndt.Rows[0]["title"].ToString(), 10, "…");
            }
        }
    }
    public string nexttitle
    {
        get
        {
            if (ndt == null)
            {
                return "没有通知了";
            }
            else
            {
                return ndt.Rows[0]["title"].ToString(); 
            }          
        }
    }


DAL层:
        #region 通过通知ID取出上一条板块为通知的记录
        /// <summary>
        /// 通过通知ID取出上一条板块为通知的记录
        /// </summary>
        /// <param name="id">通知ID</param>
        /// <returns></returns>
        public DataTable SelectAllNoticePreRecordId(string id)
        {
            DataTable dt = new DataTable();
            string cmdText = "news_selectnoticenextRecorId";
            SqlParameter[] paras = new SqlParameter[]{
                 new SqlParameter("@id",id)
             };
            dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);
            if (dt.Rows.Count>0)
            {
                return dt;
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region 通过通知ID取出下一条板块为通知的记录
        /// <summary>
        /// 通过通知ID取出下一条板块为通知的记录
        /// </summary>
        /// <param name="id">通知ID</param>
        /// <returns></returns>
        public DataTable SelectAllNoticeNextRecorId(string id)
        {
            DataTable dt = new DataTable();
            string cmdText = "news_selectnoticepreRecordId";
            SqlParameter[] paras = new SqlParameter[]{
                 new SqlParameter("@id",id)
             };
            dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);
           if (dt.Rows.Count>0)
            {
                return dt;
            }
            else
            {
                return null;
            }
        }
        #endregion
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics