在资讯详情页面中,通常都有相关资讯这个模块,那么,如果没有的话,如何添加相关资讯呢?
1、添加Repeater控件
<div class="newstj">
<ul>
<asp:Repeater ID="rp_NewsList2" runat="server">
<ItemTemplate>
<li><span><%#Eval("AddTime","{0:MM-dd}") %></span>
<a href="news_detail-<%#Eval("NewsID") %>.html" title="<%#Eval("NewsTitle") %>"><%#cutstr(Eval("NewsTitle").ToString(), 18)%></a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
2、 在news_detail.aspx.cs页面中,添加如下代码:
//相关资讯
string Splitkwds = SeoKeywords;
string[] arrstr = Splitkwds.Split(new char[] { ',', ';', ' ' });
for (int i = 0; i < arrstr.Length; i++)
{
if (i == 0)
{
NewsSearchCondition = "SeoKeywords like \'%" + arrstr[i] + "%\'";
}
else
{
NewsSearchCondition = NewsSearchCondition + " or SeoKeywords like \'%" + arrstr[i] + "%\'";
}
NewsSearchCondition = "NewsID<>" + newsID + "and (" + NewsSearchCondition + ")";
strSql = "";
strSql = "select top 12 NewsID,ClassID,NewsTitle,SEOTitle,SeoKeywords,SeoDesc,ClickTimes,AddWho,AddTime,ClassName From
cai_V_News where " + NewsSearchCondition + " order by NewsID desc";
DataView dvlist_news2 = News.QueryNews(strSql);
rp_NewsList2.DataSource = dvlist_news2;
rp_NewsList2.DataBind();
}