All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL jdbc解决自动自动增长列统一处理问题纪实_[SQL Server教程]
MS,SQL数据库的连接处理解决方案_[SQL,Server教程]
C#,2.0,套接字编程实例初探_[Asp.Net教程]
asp.net读取文本文件并加入DataTable中_[Asp.Net教程]
无法远程登入MySQL数据库的三种解决办法_php资料_编程技术
VS2005和ASP.NET2.0中使用强类型数据_[Asp.Net教程]
PHP编程常用技巧四则_php资料_编程技术
Asp.Net,加密示例_[Asp.Net教程]
ASP.NET程序中常用的三十三种代码2_[Asp.Net教程]
修改SQL Server数据库中的逻辑文件名_[SQL Server教程]
Reading number is top 10 pictures
Wild animals melee moment of life and death1
到南昌西站了1
青春清纯美女大集合1
The real super beauty2
Take you to walk into the most true north Korea rural3
含苞欲放的素颜美少女3
到南昌西站了3
Chinese paper-cut grilles art appreciation8
Wild animals melee moment of life and death2
陪睡门马睿菈自曝写真 称首拍大尺度照片2
Download software ranking
Boxer Classic video1
Kung.Fu.Panda.2
C#与.NET技术平台实战演练
Such love down(擒爱记)
The Bermuda triangle2
虚拟机汉化软件
Eclipse 4.2.1 For Win32
jdk1.6 for windows
dreamweaver8中文版
Tram sex maniac 2 (H) rar bag10
归海一刀 published in(发表于) 2014/1/30 1:10:12 Edit(编辑)
多种方法实现超长字符用-.....-代替_[Asp.Net教程]

多种方法实现超长字符用-.....-代替_[Asp.Net教程]

多种方法实现超长字符用"....."代替_[Asp.Net教程]

1、gridview

效果如图:


公用方法:
protected string Intercept(string sInput)
{
if (sInput != null && sInput != string.Empty)
{
if (sInput.Length > 10)
return sInput = sInput.Substring(0, 10) + "...";
else
return sInput;
}
return "";
}

第一种方法:在GridView的RowDataBound方法中遍历每一行数据;


protected void gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
string sGUID;
if (e.Row.RowType == DataControlRowType.DataRow)
{
sGUID = e.Row.Cells[0].Text;
//display the changed values
e.Row.Cells[0].Text = Intercept(sGUID);
}
}

第二种方法:将GridView的某一列(改变默认显示)变成模板列;


具体步骤:GridView右键-显示智能标记-编辑列-在选定的字段里面选中字段(右下角点击将此字段转换为TemplateField)
(如果你从第一个方法试到第二个方法,第二个方法完成后运行,你会发现编号这行没有数据显示,知道为什么吗?)
答案就是第一种方法里面已经改变了显示效果(cs代码),如果你再次在html代码调用Intercept(...)方法将return "",所以没有数据显示;


*注意:这里将某一列变成了模板列的时候,Html代码绑定该字段是:Text='<%# Bind("GUID") %>',这里若要运用上面的公用方法(Intercept(...)),将Bind改成Eval,具体代码请看:











第三种方法最简单:通过CSS样式来控制;
在html中加入样式表



相信大多数人会喜欢这种,不用编写代码;


2.DataList


第一种方法:在ItemDataBound(...)方法中遍历所有行
protected void dlMain_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblGUID = (Label)e.Item.FindControl("lblGUID");
System.Data.Common.DbDataRecord dbdr = (System.Data.Common.DbDataRecord)e.Item.DataItem;
//这里可以改变任何一列的数据显示
string sGUID = Convert.ToString(dbdr["GUID"]);
lblGUID.Text = Intercept(sGUID);
}
}

第二种方法:也是通过CSS样式来控制;


同上;







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.