Repeater中的“详细信息/简介”生成

我们用Repeater生成一些列表时,对于一些较长的内容一般只会显示部分的信息,如只显示20个字。
我是用以下方法实现的:


在.aspx中

<%# GenDescription(DataBinder.Eval(Container.DataItem,"Description"),20)%>




在.cs中

public string GenDescription(string description,int len)
        
{
            
if(description.Length==0)
            
{
                
return "";
            }

            
else if(description.Length>len)
            
{
                
return description.Substring(0,len)+"";
            }

            
else
            
{
                
return description;
            }

        }

原文地址:https://www.cnblogs.com/bankey/p/939711.html