我有一张新闻表(ID,Title,Content),我想实现在DataGrid中显示Title, 有时候Title的字符比较长,如果都显示会影响美观,所以我想只显示10个字符,其余的用“...”表示!还望各位教教小弟!谢谢了!
解决方案 »
- Aspose.Cells Excel 另为Html时日期变成井怎么办急急!在线等……
- allowDefinition='MachineToApplication' 的节是错误的
- 花钱有偿求一个Web打印解决方案或控件,或源码实例!
- Microsoft Visual Studio 2005 Team Suite 中文正式版到底出来没有啊??
- 高分帮帮小女子,请问我怎样生成随机数,具体如下(本人在线,问题解决立即给分):
- vs2003(c#)中使用水晶报表,如何动态的绑定字段?(web)
- 网站调试时没有问题发布后page_load()执行了两次,
- bootstrap modal与IE10不兼容,点击了不能显示弹出层,怎么解决?
- 请问怎么控制datalist的显示样式(急!急!急!在线等待)!
- 运行错误????
- 读取数据库快还是读取xml快
- .net中的问题,找不到错误,在线等
2.在itemDataBound中写
string temp=e.Item.Cell[2].Text.Trim()
if(temp.Length>10)
{
e.Item.Cell[2].Text=temp.Substring(0,10)+"...";
}
public string MyLeftFunction(string strInput,int intLen)
{
strInput=strInput.Trim();
byte[] myByte = System.Text.Encoding.Default.GetBytes(strInput);
if(myByte.Length>intLen)
{
string resultStr="";
for(int i=0;i<strInput.Length;i++)
{
byte[] tempByte=System.Text.Encoding.Default.GetBytes(resultStr);
if(tempByte.Length<intLen)
{
resultStr+=strInput.Substring(i,1);
}
else
{
break;
}
}
return resultStr+"...";
}
else
{
return strInput;
}
}
前台
<%# MyLeftFunction(DataBinder.Eval(Container, "DataItem.Title").ToString(),20) %>
{
int i = 0, j = 0;
foreach (char chr in str)
{
i += 2;
if (i > length)
{
str = str.Substring(0, j - 1) + "...";
break;
}
j++;
}
return str;
}
截取20个字(这是我经常用的一招)