GridView绑定数据时解决文字过长问题

首先,写一个抽象类,一个静态函数。
public abstract class TStringOp
{
    public static string trunc(string inStr, int len)
    {
        if (inStr.Length > len)
        {
            inStr = inStr.Substring(0, len)+"...";
        }
        return inStr;
    }
}
然后,写在数据绑定的时候调用之:
<asp:Label ID="lblIntro" runat="server" Text='<%# TStringOp.trunc(Eval("siteIntro").ToString(),20) %>'
原文地址:https://www.cnblogs.com/wangxiaohuo/p/570397.html