“Repeater”控件显示的数据如何截取长度。 数据表“nrong”中有列“title”中储存文章的标题长度50个字符,现在在页面中用“Repeater”控件显示标题,希望只显示前40个字符,要怎样操作呀? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写个扩展方法吧public static Left(this string source, int subLength){ return source == null ? string.Empty : source.SubString(0, source.Length >=subLength ? subLength : source.Length);}<%# ((string)Eval("title")).Left(40) %>或<%# new string(((string)Eval("title") ?? string.Empty).Take(40).ToArray())%> <%# Eval("title").ToString().length>50?Eval("title").ToString().length(0,47)+"...":Eval("title").ToString()%> +1SubString 截取字符串。 写个方法 public string GetTitle(object title, int length) { string strTitle = title.ToString(); if (strTitle.Length > length) { strTitle = strTitle.Substring(0, length) + "..."; } return strTitle; }数据绑定时:<%#GetTitle(Eval("Title"), 12)%> jQuery 遍历表格列问题 asp.net里文件最大上传限制是多少 求助:asp网站新闻文章标题 ,后边自动显示发布的日期, 想自动生成,代码怎么写啊? Page_Load问题 Cmd.ExecuteNonQuery错误! session问题 急!!!!部署,安装问题 行 44: <identity impersonate="true"/>求助高手 ASP.NET页面程序运行一段时间后出现问题? 2大难题,在线等待!——C# web应用程序错误,谁人能解????狂加分 谁可以给些关于“推”的技术呢?多谢了!!! discuz!nt使用 做过建行支付接口的请进
写个扩展方法吧
public static Left(this string source, int subLength)
{
return source == null ? string.Empty : source.SubString(0, source.Length >=subLength ? subLength : source.Length);
}
<%# ((string)Eval("title")).Left(40) %>
或
<%# new string(((string)Eval("title") ?? string.Empty).Take(40).ToArray())%>
<%# Eval("title").ToString().length>50?Eval("title").ToString().length(0,47)+"...":Eval("title").ToString()%>
SubString 截取字符串。
public string GetTitle(object title, int length)
{
string strTitle = title.ToString();
if (strTitle.Length > length)
{
strTitle = strTitle.Substring(0, length) + "...";
}
return strTitle;
}数据绑定时:
<%#GetTitle(Eval("Title"), 12)%>