我正在使用带有 c# 的 asp.net。我正在显示数据库表中的一些数据。该表的一列包含该特定记录的描述。我想首先显示最低限度的描述,还想添加某种阅读更多选项(例如,“阅读更多......”或“......”)。
我怎么能做这份工作?
帮助shell高度赞赏。. .
您可以使用 jquery 插件 - 这对我来说非常好 - http://dotdotdot.frebsite.nl/
您可以使用此代码:
public static string ShortDescription(string Description)
{
string result = Description;
if (result.Length > 50)
{
result = result.Substring(0, 50);
result += "....";
}
return result;
}
并使用上述方法:
<p>
<%# ShortDescription(Eval("Description").ToString())%>
<a href='ShowDescription.aspx?Id=<%# Eval("Id") %>'>Read more. . . </a>
</p>
对于纯客户端 JavaScript 解决方案,您可以将部分描述隐藏在不可见的范围内:
This is the beginning
<span style="cursor:pointer" onclick="this.nextSibling.style.display = this.nextSibling.style.display == 'none'? '': 'none'">...more...</span>
<span style="display:none">of a very very very very very very very very very very very very very long description</span>
请注意,使用此解决方案的长描述将显示在与原始短描述相同的单元格中。