DataGrid中某一列描述信息很长,显示时我只显示前十个字符。如何实现鼠标移到上面弹出层显示所有信息?急!

lijiajia 2004-08-05 05:47:51
DataGrid中某一列描述信息很长,全部显示格式会很乱。因此我在显示时我只显示了前十个字符。如何实现鼠标移到上面弹出层显示所有信息?急!
...全文
268 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
shoutor 2004-08-06
  • 打赏
  • 举报
回复
<%# DataBinder.Eval(Container, "DataItem.f_PostMemo") %>
f_PostMemo代表的就是显示DataKeyField对应的记录
「已注销」 2004-08-05
  • 打赏
  • 举报
回复
shoutor(土人制造) 的方法我也试了,没有成功
sanfv(sanfv(sanfv());) 的方法很好
如果我不是在后台的代码写public string GetShortString(string source,int n)
的方法而是写一个类,那比较方便
付:我写过的类
namespace xxx
{
处理字符串的类
}

然后using xxx
在后台代码Page_load事件前声明

protected xxx.处理的类 test=new 处理的类();

在帮定
<%#test.处理的方法(DataBinder.Eval
(Container.DataItem,"帮定列").ToString(),30)%>

WZCNet 2004-08-05
  • 打赏
  • 举报
回复
if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item))
{
if (e.Item.Cells[4].Text.Length >= 3)
{
e.Item.Cells[4].Attributes.Add("title",e.Item.Cells[4].Text);
e.Item.Cells[4].Text = e.Item.Cells[4].Text.Substring(0,3);
}
}
试验成功了,在DataGrid的ItemDataBound事件中加.
brightheroes 2004-08-05
  • 打赏
  • 举报
回复
ItemDataBound:

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If e.Item.Cells(2).Text.Length > 10 Then
e.Item.Cells(2).ToolTip = e.Item.Cells(2).Text)
e.Item.Cells(2).Text = e.Item.Cells(2).Text.Substring(0, 9) & "..."
End If
End If

End Sub
lijiajia 2004-08-05
  • 打赏
  • 举报
回复
shoutor(土人制造) 的方法我试了很久,一直没有成功。
不知道是为什么,请其他朋友再帮助我一下!感谢!
brightheroes 2004-08-05
  • 打赏
  • 举报
回复
agree with guoyan19811021(吉祥)
brightheroes 2004-08-05
  • 打赏
  • 举报
回复
agree with hdt
给你的e.Item.ToolTip绑定到字段的全部内容
给你的e.Item.Cell[3](比如说)绑定到substring(0,10)
guoyan19811021 2004-08-05
  • 打赏
  • 举报
回复
ItemDataBound:

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If e.Item.Cells(2).Text.Length > 10 Then
e.Item.Cells(2).Attributes.Add("title", e.Item.Cells(2).Text)
e.Item.Cells(2).Text = e.Item.Cells(2).Text.Substring(0, 9) & "..."
End If
End If

End Sub
真相重于对错 2004-08-05
  • 打赏
  • 举报
回复
toollip
jsljy 2004-08-05
  • 打赏
  • 举报
回复
绑定<A title="<%#全部%>"><%#gettitle(返回前面10个字符)%> </A>
sanfv 2004-08-05
  • 打赏
  • 举报
回复
<1>
<%# GetShortString(DataBinder.Eval(Container.DataItem,"title").ToString(),10)%>


public string GetShortString(string source,int n)

{
string tmp;
if (source.Length>n)
tmp=source.Substring(0,n)+"..";
else
tmp=source;
return tmp;

}

<2>
<a href="*.aspx" title=<%# DataBinder.Eval(Container, "title") %>
>
「已注销」 2004-08-05
  • 打赏
  • 举报
回复
只显示了前十个字符到是不难,你在后台代码写个方法就可以了,但是小下面的功能就麻烦,楼上的代码<%# DataBinder.Eval(Container, "DataItem.f_PostMemo") %>
对应是什么啊??
shoutor 2004-08-05
  • 打赏
  • 举报
回复
--function.js(在页面中包含:<script src=Function.js></script>)

function MM_reloadPage(init)
{ //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d)
{ //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers()
{ //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}

---在datagrid中添加模板列(设置相应的DataKeyField,把f_PostID变成自己的即可)
<asp:TemplateColumn>
<ItemTemplate>
<div onMouseOver="MM_showHideLayers('layer<%# DataBinder.Eval(Container, "DataItem.f_PostID") %>','','show')" onMouseOut="MM_showHideLayers('layer<%# DataBinder.Eval(Container, "DataItem.f_PostID") %>','','hide')">
<font color=blue><U>备注</U></font>
</div>
<span id='layer<%# DataBinder.Eval(Container, "DataItem.f_PostID") %>' style="position:absolute; left=420; top:100; width:300; z-index:1; layer-background-color: #FFFFCC; border: 1px none #000000; visibility: hidden;">
<table width="100%" border="0" cellpadding="10" cellspacing="1" bgcolor="#000000">
<tr>
<td bgcolor="#FFFFCC">
<%# DataBinder.Eval(Container, "DataItem.f_PostMemo") %>
</td>
</tr>
</table>
</span>
</ItemTemplate>
</asp:TemplateColumn>

62,073

社区成员

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

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

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

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