在我们用的控件中,有时要使用到gridView,但是在前台显示的时候不希望全部显示,这时候就会碰到截取字符串的问题

经小编总结, 解决如下:

1.现在后台编写截取方法:

 

View Code
 1 public string Cut(string text, int count)
 2         {
 3             if (text.Length < count)
 4             {
 5                 return text;
 6             }
 7             else
 8             {
 9                 return text.Substring(0, count) + "...";
10             }
11         }

2.gridView 设计中进行如下的操作:

【ASP.NET】在gridView中解决截取字符串问题

【ASP.NET】在gridView中解决截取字符串问题

【ASP.NET】在gridView中解决截取字符串问题

【ASP.NET】在gridView中解决截取字符串问题

【ASP.NET】在gridView中解决截取字符串问题

【ASP.NET】在gridView中解决截取字符串问题

注:将上图位置的表达式换成下方的!

【ASP.NET】在gridView中解决截取字符串问题

 

 

结果就是变成超过20的用“...” 来显示了!

【ASP.NET】在gridView中解决截取字符串问题

好了,问题解决了,好好编程把!

相关文章:

  • 2021-06-14
  • 2021-05-29
  • 2022-12-23
  • 2021-07-17
  • 2021-07-28
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
猜你喜欢
  • 2022-02-25
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2023-04-03
  • 2022-03-09
相关资源
相似解决方案