新闻hot活news设置问题时间:2022-11-03 08:52:50之前的做法用引用System.Text;命名空间。 定义StringBuilder对了来拼接完成新闻标题后面就news 或hot代码如下: BJNews NewsInfo = new BJNews(); NewsInfo.ParentID = 64; NewsInfo.IsNew = true; DataTable DT = WebManager.List(NewsInfo, "", "top 8 [ID],[Title],[CreateTime]", "&parentid=&isnew=", "[CreateTime] desc"); StringBuilder Builder = new StringBuilder(); if (DT.Rows.Count >= 6) { Builder.Append("<table width='289' height='189' border='0' cellspacing='0' cellpadding='0'>"); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a><img src="img/new.gif" mce_src="img/new.gif" /></td></tr>", DT.Rows[0][0].ToString(),FormUtil.SubString(DT.Rows[0][1].ToString(),16)); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a><img src="img/new.gif" mce_src="img/new.gif" /></td></tr>", DT.Rows[1][0].ToString(), FormUtil.SubString(DT.Rows[1][1].ToString(), 16)); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a><img src="img/new.gif" mce_src="img/new.gif" /></td></tr>", DT.Rows[2][0].ToString(), FormUtil.SubString(DT.Rows[2][1].ToString(), 16)); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a><img src="img/new.gif" mce_src="img/new.gif" /></td></tr>", DT.Rows[3][0].ToString(), FormUtil.SubString(DT.Rows[3][1].ToString(), 16)); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a><img src="img/new.gif" mce_src="img/new.gif" /></td></tr>", DT.Rows[4][0].ToString(), FormUtil.SubString(DT.Rows[4][1].ToString(), 16)); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a></td></tr>", DT.Rows[5][0].ToString(), FormUtil.SubString(DT.Rows[5][1].ToString(), 18)); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a></td></tr>", DT.Rows[6][0].ToString(), FormUtil.SubString(DT.Rows[6][1].ToString(), 18)); Builder.AppendFormat("<tr><td width='46' align='center'> <img src="img/icon2.jpg" mce_src="img/icon2.jpg" width='9' height='9' /></td><td width='243' height='20'><a target='_blank' href="newsDetail.aspx?id={0}" mce_href="newsDetail.aspx?id={0}">{1}</a></td></tr></table>", DT.Rows[6][0].ToString(), FormUtil.SubString(DT.Rows[6][1].ToString(), 18)); } return Builder.ToString(); 后面发现其实用个三元运算符可以解决这个问题。新代码如下 <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="26" align="center"><img src="images/icon.jpg" mce_src="images/icon.jpg" width="9" height="9" /></td> <td width="671" height="26" align="left"><a href="news_detail.aspx?id=<%#Eval(" mce_href="news_detail.aspx?id=<%#Eval("Id")%>"><%#Component.Common.FormUtil.InterceptCharacter(Eval("Title").ToString(),110)%> </a><%#(bool.Parse(Eval("IsNew").ToString())==true)?"<img src="images/dot.gif" mce_src="images/dot.gif" />":" " %></td> <td width="81" align="center"><%#Eval("CreateTime","{0:d}")%></td> </tr> <tr> <td colspan="3" align="left" ><img src="images/x.jpg" mce_src="images/x.jpg" /></td> </tr> </table> </ItemTemplate> </asp:Repeater> 如何你有更好的想法,欢迎拍砖