因绑定的数据有时会很长,当一次写入时会把某一行撑得非常的高!不太美观,所以希望能只显示部份数据,当鼠标移到某一行的某一列时,才将当前单元格的数据动态的显示出来!请各位帮忙!

解决方案 »

  1.   

    加一个 cssclass 其中写:
    white-space: nowrap;
    这样就不会折行.如果要超出的不显示,那么可以用
    overflow: hidden; 样式。
      

  2.   

    TO:inelm(木野狐) 
    我需要新开一个Css文件吗?
    可以这样写吗?<ItemStyle CssClass="overflow: hidden;"></ItemStyle>Css文件的用法我不太熟!
    我需要的是不要撑大的我列宽,也不要回行!
    谢谢!
      

  3.   

    在DataGrid属性-->列-->
    在数据格式设置表达式中输入
    <DIV style='overflow: hidden;width: 100px;'><noBR>{0}</noBR></DIV>
    这样列不会被撑破,字符也完整~
      

  4.   

    列中这样写:在属性设计中加入模板列绑定数据后用方法将字符截取。如下代码:
    //截断字符串
    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>
      

  5.   

    <html>
    <head>
    ...
    <style type="text/css">
    .hidden {overflow: hidden;}
    </style>
    </head>
    <body>
    <asp:DataGrid....>
    ...
    <ItemStyle CssClass="hidden"></ItemStyle>
    ...
    </asp:DataGrid>
    </body>
    </html>
      

  6.   

    在DataGrid属性-->列-->
    在数据格式设置表达式中输入
    <DIV style='overflow: hidden;width: 100px;'><noBR>{0}</noBR></DIV>
    这样列不会被撑破,字符也完整~
    鼠标经过时再加Tool~~
      

  7.   

    用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;
    }
      

  8.   

    还是不行啊!
    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>">
    的样式!有没有办法解决它?
      

  9.   

    可以在绑定的时候用~
    比如: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的内容
                                }
    }