TruncationColumn 字符串超过行数的宽度用省略号代替

//GridView行数据绑定事件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow) //如果是数据行
   {
      string content = e.Row.Cells[2].Text; //取指定列值
      e.Row.Cells[2].Text = SubStr(content, 10);//调用自定义方法SubStr处理列值
   }
}

public string SubStr(string str, int len)
{
   if (str.Length <= len)
   {
      return str;
   }
   string newStr = str.Substring(0, len);//不区分字符和汉字
   newStr += "...";
   return newStr;
}

原文地址:https://www.cnblogs.com/Yellowshorts/p/2867804.html