首页 > 其他 > 详细

数据绑定控制字数的方法

时间:2014-09-06 13:34:33      阅读:171      评论:0      收藏:0      [点我收藏+]

方法一:

在Sql Server里控制:

使用SQL中的函数Left 和Right ,Sql 语句:select left(你的字段名,你要显示的字数)from Table

方法二:

 在ASP.NET页面中设计代码实现:

数据直接绑定时控制

1  <%# DataBinder.eval_r(Container.DataItem,"title").ToString().Length>20?DataBinder.eval_r(Container.DataItem,"title").ToString().Substring(0,20)+"...":DataBinder.eval_r(Container.DataItem,"title").ToString()%>

或简约写法如下:

<%#eval_r("Content").ToString().Length>20?eval_r("Content").ToString().Substring(0,20) + "...":eval_r("Content").ToString()%>

2  或者绑定方法

 1  public   static   string   InterceptStr(string   str,   int   lenght) 

 2                { 

 3                        if   (str.Length   >   lenght) 

 4                        { 

 5                                return   str.Substring(0,   lenght   -   3)   +   "... "; 

 6                        } 

 7                        else 

 8                        { 

 9                                return   str; 

10                        } 

11                } 

转载自:http://blog.sina.com.cn/s/blog_4d96ee050100oso9.html

数据绑定控制字数的方法

原文:http://www.cnblogs.com/su1643/p/3959321.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!