<td><%# Eval("shouhuorenNote")%></td>比如我这shouhuorenNote字段内容很长。。我要想截取开头前10个字后面再+.....像这种怎么写?比如“天天天天天天天天天天......”我写成<td><%# Eval("shouhuorenNote").ToString ().Substring (0,10)%></td>不行,会提示"索引和长度必须引用该字符串内的位置。参数名: length" 这是为什么呢?反正意思就是如果lenth<10,就正常显示数据。。如果大于10,就显示成“天天天天天天天天天天......”这种怎么写?

解决方案 »

  1.   

    在cs文件里写一个public方法
    比如
    public string CutString(string value)
    {
        if(value.lengh>100)
        {
            return value.substring(0,100)+"...";
         }
        else
        {
           return value;
         }
    }前台调用
    <td><%# CutString( Eval("shouhuorenNote").ToString())%></td>
      

  2.   

    本帖最后由 ojlovecd 于 2009-12-15 17:55:35 编辑
      

  3.   

       public static string subText(string text, int maxLength)
            {
                text = text.Trim();
                if (string.IsNullOrEmpty(text))
                    return string.Empty;
                if (maxLength > 0)
                {
                    if (text.Length > maxLength)
                        text = text.Substring(0, maxLength);
                }
                return text;
            }
      

  4.   

    是不是因为shouhuorenNote的字符长度小于10啊~
      

  5.   

    三目运算符,取代if else 简化代码 支持