来源:http://topic.csdn.net/u/20090320/00/8a8401e7-cc4b-4426-a38f-02aa5f52595a.html#replyachor
Method 1:
可以在GridView的RowDataBound事件中调用以下函数,当这个字段字符超过maxStrLength时用...代替,而全部字符可显示在ToolTip 中
public void OmitGridInfo(System.Web.UI.WebControls.GridViewRowEventArgs e, int[] cellIndexs, int maxStrLength)
{
string CellText = string.Empty;
for (int i = 0; i < cellIndexs.Length; i++)
{
CellText = e.Row.Cells[cellIndexs[i]].Text.Trim();
if (CellText.Length > maxStrLength)
{
e.Row.Cells[cellIndexs[i]].Text = CellText.Substring(0, maxStrLength - 1) + " <strong style="Color:blue" mce_style="Color:blue"> ... </strong>";
e.Row.Cells[cellIndexs[i]].ToolTip = CellText;
}
}
}
{
string CellText = string.Empty;
for (int i = 0; i < cellIndexs.Length; i++)
{
CellText = e.Row.Cells[cellIndexs[i]].Text.Trim();
if (CellText.Length > maxStrLength)
{
e.Row.Cells[cellIndexs[i]].Text = CellText.Substring(0, maxStrLength - 1) + " <strong style="Color:blue" mce_style="Color:blue"> ... </strong>";
e.Row.Cells[cellIndexs[i]].ToolTip = CellText;
}
}
}
Method 2:
<%# MyContent((string)Eval("Content")) %>
protected string MyContent(string input)
{
if(input.length > 0){
return input.Substring(0,5);
}else{
return input;
}
}
{
if(input.length > 0){
return input.Substring(0,5);
}else{
return input;
}
}
Method 3:
一般的文字截断(适用于内联与块):
.text-overflow {
display:block;/*内联对象需加*/
width:31em;/*指定宽度*/
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 强制在同一行内显示所有文本,直到文本结束或者遭遇 br 对象。不换行 */
overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
text-overflow:ellipsis;/* IE 专有属性,当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/
}
display:block;/*内联对象需加*/
width:31em;/*指定宽度*/
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 强制在同一行内显示所有文本,直到文本结束或者遭遇 br 对象。不换行 */
overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
text-overflow:ellipsis;/* IE 专有属性,当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/
}
浙公网安备 33010602011771号