标签:
int bg_id = 0;
//第一步:获取文章id,并判断是否为null
if (Request.QueryString["bgid"]!=null)
{
bg_id =Convert.ToInt32(Request.QueryString["bgid"]);
ST_StarNew st= ST_StarNewManager.GetST_StarNewBySs_Id(bg_id);
Page.Header.Title = st.Ss_Title + “这里为页面标题";
titleDiv.InnerHtml = " <a href=‘.‘>首页</a> > <a href=‘‘>明星八卦</a> > "+st.Ss_Title;
bg_title.InnerHtml = st.Ss_Title + "<br /><span>时间:" + st.Ss_PostDate.ToString() + " 来源:" + st.Ss_source + " 点击: " + st.Ss_click + "次</span>"; //标题及相关信息
if (count.Length > 100)
{
zai_yao.InnerHtml = PubJs.StripHT(st.Ss_Content).Substring(0, 100); //摘要.过滤html代码
}
else {
zai_yao.InnerHtml = PubJs.StripHT(st.Ss_Content); //摘要.过滤html代码
} //八卦正文
//第二步:通过正则表达式按指定的字符串进行分割,此时须导入命名空间using System.Text.RegularExpressions;
string[] resultString = Regex.Split(st.Ss_Content, "#dsj#", RegexOptions.IgnoreCase);
if (resultString.Length > 1)
{
for (int i = 1; i <= resultString.Length; i++)
{
pageStr.InnerHtml += "<a href=‘star.aspx?bgid="+bg_id+"&page=" + i + "‘>" + i + "</a>"; //分页
}
}
if (Request.QueryString["page"] != null)
{
int page = Convert.ToInt32(Request.QueryString["page"]);
count_bg.InnerHtml = resultString[page-1]; //已 #dsj# 进行分割,并显示第一页,数组下标从0开始
}
else {
count_bg.InnerHtml = resultString[0]; //已 #dsj# 进行分割,并显示第一页
}
//下一篇:这是下一遍标题
// 下一篇:这是下一遍标题
upBg.InnerHtml = ST_StarNewManager.GetSt_starBySs_idOrUp(bg_id, 1); //上一篇下一篇
}
以下是PubJs类里去除html代码的方法
/// <summary>
/// 除去html代码
/// </summary>
/// <param name="strHtml"></param>
/// <returns></returns>
public static string StripHT(string strHtml)
{
//导入命名空间using System.Text.RegularExpressions;
Regex regex=new Regex("<.+?>",RegexOptions.IgnoreCase);
string strOutput=regex.Replace(strHtml,"");
return strOutput;
}
/// <summary>
/// 获取文章的上一篇和下一篇,返回字符串
/// </summary>
/// <returns></returns>
public static String GetSt_starBySs_idOrUp(int ss_id, int uponType)
{
//方法一:通过存储过程
//SqlCommand comm = new SqlCommand();
//comm.Connection = dsj.DAL.DBHelper.Connection;
//comm.CommandText = "Proc_GetBg_SsId";//存储过程名
//comm.Parameters.Add(new SqlParameter("@Ss_Id", SqlDbType.Int));//Id
//comm.Parameters[0].Value = ss_id;
//comm.Parameters.Add(new SqlParameter("@upOndown", SqlDbType.Int));//类型
//comm.Parameters[1].Value = uponType;
//comm.CommandType = CommandType.StoredProcedure;
//SqlDataAdapter dataAdapter = new SqlDataAdapter(comm);
//DataSet ds = new DataSet();
//dataAdapter.Fill(ds);
//return ds;
//方法二:普通sql语句
string onAndDonw = string.Empty;
string sql = "";
sql = "select * from ST_StarNews where Ss_Id = (select MAX(Ss_Id) from ST_StarNews where Ss_Id<@Ss_Id)";
SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Ss_Id", ss_id));
if (reader.Read())
{
onAndDonw = "上一篇:<a href=‘star.aspx?bgid=" + Convert.ToInt32(reader["Ss_Id"]) + "‘>" + reader["Ss_Title"].ToString() + "</a>";
reader.Close();
}
else
{
reader.Close();
}
sql = "select * from ST_StarNews where Ss_Id=(select MIN(Ss_Id) from ST_StarNews where Ss_Id>@Ss_Id)";
SqlDataReader reader2 = DBHelper.GetReader(sql, new SqlParameter("@Ss_Id", ss_id));
if (reader2.Read())
{
onAndDonw += " 下一篇:<a href=‘star.aspx?bgid=" + Convert.ToInt32(reader["Ss_Id"]) + "‘>这是下一遍标题</a>";
reader2.Close();
}
else
{
reader2.Close();
}
return onAndDonw;
}
比较长的文章进行分页显示
标签:
原文地址:http://www.cnblogs.com/ysz12300/p/5494756.html