怎么设置GridView的单元格在内容显示超过长度的时候用省略号代替而不是换行当鼠标移上去的时候将影藏的内容提示出来

wangke_1987 2010-10-24 08:00:40
能不能通过设置属性来实现

不能的话请给出代码谢谢
...全文
1100 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookyzlr 2010-10-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 koukoujiayi 的回复:]
最简单的可以通过CSS来设置省略号,
鼠标移上全部显示用ToolTip,
1.CSS:
<style type="text/css">
.mlength
{
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
-o-text-overflow: ellipsi……
[/Quote]
顶顶顶!学习了。
Tanhualin 2010-10-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 koukoujiayi 的回复:]
#3楼 得分:0回复于:2010-10-24 20:39:10最简单的可以通过CSS来设置省略号,
鼠标移上全部显示用ToolTip,
1.CSS:
<style type="text/css">
.mlength
{
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
}
</style>

2.设置GeidView某一字段为模板列并设置css,如:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("字段") %>' CssClass="mlength"></asp:Label>

3.后台设置tooltip:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Label)e.Row.Cells[0].FindControl("Label1")).ToolTip = ((Label)e.Row.Cells[0].FindControl("Label1")).Text;
}
}
[/Quote]

up...
tobypy1987 2010-10-25
  • 打赏
  • 举报
回复
3楼正解。。可以结贴了
  • 打赏
  • 举报
回复
方法还是有几种的、 根据自己的想法来看、
poppinH 2010-10-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 koukoujiayi 的回复:]
最简单的可以通过CSS来设置省略号,
鼠标移上全部显示用ToolTip,
1.CSS:
<style type="text/css">
.mlength
{
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
-o-text-overflow: ellipsi……
[/Quote]

学习了...!~
chen8410 2010-10-24
  • 打赏
  • 举报
回复
<%# Eval("title").ToString().Length>100?Eval("title").ToString().SubString(0,100)+"...":Eval("title").ToString()%>
koukoujiayi 2010-10-24
  • 打赏
  • 举报
回复
3楼补充,tooltip也可以前台设置,如:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("字段") %>' CssClass="mlength" ToolTip='<%# Eval("字段") %>'></asp:Label>
lll00ooo_Hui 2010-10-24
  • 打赏
  • 举报
回复
可以用CSS来解决
yingzhilian2008 2010-10-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 koukoujiayi 的回复:]
最简单的可以通过CSS来设置省略号,
鼠标移上全部显示用ToolTip,
1.CSS:
<style type="text/css">
.mlength
{
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
-o-text-overflow: ellipsi……
[/Quote]不错
koukoujiayi 2010-10-24
  • 打赏
  • 举报
回复
最简单的可以通过CSS来设置省略号,
鼠标移上全部显示用ToolTip,
1.CSS:
<style type="text/css">
.mlength
{
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
}
</style>

2.设置GeidView某一字段为模板列并设置css,如:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("字段") %>' CssClass="mlength"></asp:Label>

3.后台设置tooltip:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Label)e.Row.Cells[0].FindControl("Label1")).ToolTip = ((Label)e.Row.Cells[0].FindControl("Label1")).Text;
}
}
huangwenquan123 2010-10-24
  • 打赏
  • 举报
回复
用三元运算符!截取字符串,当超过你指定的长度后截取
<%# Eval("title").ToString().length>100?Eval("title").ToString().length(0,100)+"...":Eval("title").ToString()%>
wuyq11 2010-10-24
  • 打赏
  • 举报
回复
<%# Eval("title").ToString().length>100?Eval("title").ToString().length(0,100):Eval("title").ToString()%>
title='<%# Eval("title")%>'
或onmousemove弹出DIV显示详细信息

string str = e.Row.Cells[1].Text;
e.Row.Cells[1].Text =str.Length >100? str.Substring(0, 100) :str;

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧