GridView中HyperLinkField怎么限制字数的显示

[复制链接]
查看11 | 回复1 | 2010-3-19 14:43:09 | 显示全部楼层 |阅读模式
GridView中HyperLinkField的字数这样控制是没有效果的,里面的链接生成到Html中是作为一个标签存在的,要在RowDataBound中控制HyperLinkField中的字数,需要这样:
if (e.Row.RowType == DataControlRowType.DataRow)//不遍历行头和行尾
{
e.Row.Cells[1].ToolTip = ((HyperLink)e.Row.Cells[1].Controls[0]).Text;
if (((HyperLink)e.Row.Cells[1].Controls[0]).Text.Length > 12)
{
((HyperLink)e.Row.Cells[1].Controls[0]).Text =((HyperLink)e.Row.Cells[1].Controls[0]).Text.Substring(0, 12) + "... ";
}
}
回复

使用道具 举报

千问 | 2010-3-19 14:43:09 | 显示全部楼层
//DataStr 需要被截取的字符串,StrLenght 需要截取的长度public string CellLenghtCtr(object DataStr, int StrLenght)
{
StrLenght = Utinity.User.GetStringLength(DataStr.ToString().Trim(), StrLenght);
if (DataStr.ToString().Length > StrLenght)
{
StrLenght = StrLenght - 3;
return DataStr.ToString().Substring(0, StrLenght) + "...";
}
return DataStr.ToString();
}
///
/// 获取字符串真实长度(中英文数字标点)
///
///
///
public static int GetStringLength(string content, int maxLength)
{
ASCIIEncoding En = new ASCIIEncoding();
Byte[] B = En.GetBytes(content);
int Length = 0;
int count = 0;
for (int i = 0; i = maxLength)
break;
}
return count;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行