可以用CellFormatting, 当字符过长时, 就Format成带"..."的, 但Cell里面的内容是原字符串内容, 并把ToolTipText设成原字符串内容就行

解决方案 »

  1.   

    <%# (DataBinder.Eval(Container.DataItem, "userPassword").ToString()).Length>1?
    DataBinder.Eval(Container.DataItem, "userPassword").ToString()+"...":
    DataBinder.Eval(Container.DataItem, "userPassword")%>
      

  2.   

    用CSS控制:overflow : ellipsis ;
    text-overflow : hidden ;
      

  3.   

    =================
     GridView 如果 你将那一列 设置为模版列的话..
    <asp:TemplateField HeaderText=" 内容 ">                                     
                                         <ItemStyle HorizontalAlign="Center" /> 
                                         <HeaderStyle HorizontalAlign="Center" Width="15%" /> 
                                         <ItemTemplate> 
                                             <%# CutString(Convert.ToString(Eval("Content")), 20)%> 
                                         </ItemTemplate> 
                                   </asp:TemplateField>
    后台代码中 
     if (str.Length > len)
            {
                return str.Substring(0, len) + "...";
            }
            else
            {
                return str;
            }如果是绑定列的哗..需要将 GridView 绑定之后. 循环遍历那一列..截取..
    public static string res(str,len)
    {
     if (str.Length > len)
            {
                return str.Substring(0, len) + "...";
            }
            else
            {
                return str;
            }
    }