请教一下,如何让DataGrid中的绑定列填入数据太长时不变高?当鼠标移到某一列时显示它的完全数据?闷,以前看见过的!现在找不到了! 因绑定的数据有时会很长,当一次写入时会把某一行撑得非常的高!不太美观,所以希望能只显示部份数据,当鼠标移到某一行的某一列时,才将当前单元格的数据动态的显示出来!请各位帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 加一个 cssclass 其中写:white-space: nowrap;这样就不会折行.如果要超出的不显示,那么可以用overflow: hidden; 样式。 TO:inelm(木野狐) 我需要新开一个Css文件吗?可以这样写吗?<ItemStyle CssClass="overflow: hidden;"></ItemStyle>Css文件的用法我不太熟!我需要的是不要撑大的我列宽,也不要回行!谢谢! 在DataGrid属性-->列-->在数据格式设置表达式中输入<DIV style='overflow: hidden;width: 100px;'><noBR>{0}</noBR></DIV>这样列不会被撑破,字符也完整~ 列中这样写:在属性设计中加入模板列绑定数据后用方法将字符截取。如下代码: //截断字符串 public string Short(string str,int intLength) { string strReturn=str; if(str.Length>intLength) { strReturn=str.Substring(0,intLength)+"..."; } return strReturn; }//模板列加入:<asp:HyperLink id=HyperLink1 runat="server" Text='<%# Short(Convert.ToString(DataBinder.Eval(Container,"DataItem.affichetitle")),15) %>' ForeColor="Gray" NavigateUrl='<%# @"News.aspx?id="+DataBinder.Eval(Container, "DataItem.afficheid")%>' ToolTip='<%# DataBinder.Eval(Container,"DataItem.affichetitle") %>' Target="_blank"></asp:HyperLink> <html><head>...<style type="text/css">.hidden {overflow: hidden;}</style></head><body><asp:DataGrid....>...<ItemStyle CssClass="hidden"></ItemStyle>...</asp:DataGrid></body></html> 在DataGrid属性-->列-->在数据格式设置表达式中输入<DIV style='overflow: hidden;width: 100px;'><noBR>{0}</noBR></DIV>这样列不会被撑破,字符也完整~鼠标经过时再加Tool~~ 用ToolTip属性<asp:Label runat="server" ToolTip='<%# DataBinder.Eval(Container.DataItem, "Content").ToString() %>' Text='<%# LeftStr(DataBinder.Eval(Container.DataItem, "Content").ToString(),20) %>' ID="Label2"> </asp:Label>public string LeftStr(string InStr,Int Length){ if(InStr.Length>Length) InStr=InStr.substring(InStr,Length)+"..."; return InStr;} 还是不行啊!TO: inelm(木野狐) 你的这个方法还是不能实现啊!DataGrid一样会出现回行的!郁闷啊TO: y3q3() <asp:BoundColumn DataField="EndDate" HeaderText="要求结束时间" DataFormatString="<DIV style='overflow: hidden;width: 90px;'><noBR>{0:yyyy-MM-dd HH:mm}</noBR></DIV>"> <ItemStyle Width="100px"></ItemStyle></asp:BoundColumn>用你这种方法可以保证了Datagrid的列不被撑大,但是当我要用ToolTip的时候就会整个显示"<DIV style='overflow: hidden;width: 90px;'><noBR>2004-05-29 09:00</noBR></DIV>">的样式!有没有办法解决它? 可以在绑定的时候用~比如:private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemIndex!=-1) { e.Item.ToolTip=e.Item.Cells[1].Text+e.Item.Cells[2].Text;//当然也可以是其他Cell的内容 } } .resx资源文件碰到的怪异问题/.寻高手解答!!!! objectdatasource参数的问题 DataGrid 的问题[请朋友们来看看 急等] 如何将mht文件转换为html? 使网页无法后退的方法 一个小问题 装了win2003后,IIS的FrontPage扩展配制不了(已装了FrontPage扩展),帮帮忙呀! 请教高手.....帮忙看看.....急救.......... 请哪位有空解决一个问题? XDE安装完后怎样用呀 请教大家动态改变用户控件属性的问题中关于private和protected的问题 求FreeTextBox的vb源码
white-space: nowrap;
这样就不会折行.如果要超出的不显示,那么可以用
overflow: hidden; 样式。
我需要新开一个Css文件吗?
可以这样写吗?<ItemStyle CssClass="overflow: hidden;"></ItemStyle>Css文件的用法我不太熟!
我需要的是不要撑大的我列宽,也不要回行!
谢谢!
在数据格式设置表达式中输入
<DIV style='overflow: hidden;width: 100px;'><noBR>{0}</noBR></DIV>
这样列不会被撑破,字符也完整~
//截断字符串
public string Short(string str,int intLength)
{
string strReturn=str;
if(str.Length>intLength)
{
strReturn=str.Substring(0,intLength)+"...";
}
return strReturn;
}
//模板列加入:
<asp:HyperLink id=HyperLink1 runat="server" Text='<%# Short(Convert.ToString(DataBinder.Eval(Container,"DataItem.affichetitle")),15) %>' ForeColor="Gray" NavigateUrl='<%# @"News.aspx?id="+DataBinder.Eval(Container, "DataItem.afficheid")%>' ToolTip='<%# DataBinder.Eval(Container,"DataItem.affichetitle") %>' Target="_blank">
</asp:HyperLink>
<head>
...
<style type="text/css">
.hidden {overflow: hidden;}
</style>
</head>
<body>
<asp:DataGrid....>
...
<ItemStyle CssClass="hidden"></ItemStyle>
...
</asp:DataGrid>
</body>
</html>
在数据格式设置表达式中输入
<DIV style='overflow: hidden;width: 100px;'><noBR>{0}</noBR></DIV>
这样列不会被撑破,字符也完整~
鼠标经过时再加Tool~~
<asp:Label runat="server" ToolTip='<%# DataBinder.Eval(Container.DataItem, "Content").ToString() %>' Text='<%# LeftStr(DataBinder.Eval(Container.DataItem, "Content").ToString(),20) %>' ID="Label2">
</asp:Label>public string LeftStr(string InStr,Int Length)
{
if(InStr.Length>Length)
InStr=InStr.substring(InStr,Length)+"...";
return InStr;
}
TO: inelm(木野狐)
你的这个方法还是不能实现啊!DataGrid一样会出现回行的!
郁闷啊TO: y3q3()
<asp:BoundColumn DataField="EndDate" HeaderText="要求结束时间" DataFormatString="<DIV style='overflow: hidden;width: 90px;'><noBR>{0:yyyy-MM-dd HH:mm}</noBR></DIV>">
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundColumn>
用你这种方法可以保证了Datagrid的列不被撑大,但是当我要用ToolTip的时候就会整个显示
"<DIV style='overflow: hidden;width: 90px;'><noBR>2004-05-29 09:00</noBR></DIV>">
的样式!有没有办法解决它?
比如:private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex!=-1)
{
e.Item.ToolTip=e.Item.Cells[1].Text+e.Item.Cells[2].Text;//当然也可以是其他Cell的内容
}
}