关于文章标题截取规定字数:(c#)
------------------------
在aspx文件中加入函数:
------------------------
<script language="c#" runat="server">
public string leftStr(string str)
{
string strLeft = "";
if (str.Length > 20)
{
strLeft = str.Substring(0,18)+"..";
}
else
{
strLeft = str;
}
return strLeft;
}
</script>
------------
使用函数:
------------
<%#leftStr(Convert.ToString(DataBinder.Eval(Container.DataItem, "title")))%>
------------
使用心得:
上面使用中使用了一个convert的函数,强制转换数据为文本,如果不加,报错信息为:
最匹配的重载方法具有一些无效参数...