日期:2014-05-17 浏览次数:20609 次
写个扩展方法吧
public static Left(this string source, int subLength)
{
    return source == null ? string.Empty : source.SubString(0, source.Length >=subLength ? subLength : source.Length);
}
<%# ((string)Eval("title")).Left(40) %>
或
<%# new string(((string)Eval("title") ?? string.Empty).Take(40).ToArray())%>
------解决方案--------------------
写个方法
  public string GetTitle(object title, int length)
       {
           string strTitle = title.ToString();
           if (strTitle.Length > length)
           {
               strTitle = strTitle.Substring(0, length) + "...";
           }
           return strTitle;
       }
数据绑定时:
<%#GetTitle(Eval("Title"), 12)%>