下一条

来源:互联网 发布:2017年餐饮业数据分析 编辑:程序博客网 时间:2024/06/12 00:57
#region 上一条下一条
        /// <summary>
        /// 上一条下一条
        /// </summary>
        /// <param name="replaceHtml">要替换的字符串</param>
        /// <param name="id">id</param>
        /// <param name="ds">所在数据集</param>
        /// <param name="channel1">类别实体</param>
        /// <returns>返回结果的字符串</returns>
        public static string PerOrNext(string replaceHtml, int id, DataSet ds, DtCms.Model.Channel channel1)
        {
            //设置datatable的主键值
            DataColumn[] dcs = { ds.Tables[0].Columns["Id"] };
            ds.Tables[0].PrimaryKey = dcs;


            //当前id所在datatable中的索引
            int j = ds.Tables[0].Rows.IndexOf(ds.Tables[0].Rows.Find(id));


        
                //上一章
                if (j - 1 < 0)
                {
                    replaceHtml = replaceHtml.Replace("@PerTitle@", "没有上一条");
                    replaceHtml = replaceHtml.Replace("@PerHref@", "javascript:void(0)");
                }
                else
                {
                    replaceHtml = replaceHtml.Replace("@PerTitle@", ds.Tables[0].Rows[j - 1]["Title"] != null ? ds.Tables[0].Rows[j - 1]["Title"].ToString() : "");
                    replaceHtml = replaceHtml.Replace("@PerHref@", "/" + channel1.WebPath + ds.Tables[0].Rows[j - 1]["Id"] != null ? ds.Tables[0].Rows[j - 1]["Id"].ToString() : "");
                }


                //下一条
                if (j < ds.Tables[0].Rows.Count - 1)
                {
                    replaceHtml = replaceHtml.Replace("@NextTitle@", ds.Tables[0].Rows[j + 1]["Title"] != null ? ds.Tables[0].Rows[j + 1]["Title"].ToString() : "");
                    replaceHtml = replaceHtml.Replace("@NextHref@", "/" + channel1.WebPath + ds.Tables[0].Rows[j + 1]["Id"] != null ? ds.Tables[0].Rows[j + 1]["Id"].ToString() : "");
                }
                else
                {
                    replaceHtml = replaceHtml.Replace("@NextTitle@", "没有下一条");
                    replaceHtml = replaceHtml.Replace("@NextHref@", "javascript:void(0)");
                }




            return replaceHtml;


        }
        
        #endregion
0 0