在做新聞中心時,輸出的標題一般會限制顯示的字符長度,超出的部分用.....代替!
這是我在網上找到的最簡單的一個方法:
首先創建一個類,代碼如下:
public string TitleShow(object article)
{
string TitleShow = (string)article;
if (TitleShow.Length > 16)
TitleShow = TitleShow.Substring(0, 16) + "...";
return TitleShow;
}
然後,肯定是調用啦,代碼如下:
<%#TitleShow(DataBinder.Eval(Container.DataItem, "title"))%>