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