后台.CS文件添加静态方法:
public static string StringTruncat(string oldStr, int maxLength,string endWith)
{
if (string.IsNullOrEmpty(oldStr))
{
return oldStr + endWith;
}
if (maxLength<1)
{
throw new Exception("返回的字符串长度必须大于[0]");
}
if (oldStr.Length>maxLength)
{
string strTem = oldStr.Substring(0, maxLength);
if (string .IsNullOrEmpty(endWith))
{
return strTem;
}
else
{
return strTem + endWith;
}
}
return oldStr;
}
前端.aspx文件调用
调用StringTruncat在TD中显示15个字符,其余字符以...代替显示