通过div样式控制单元格文本超长省略

 

通过我们在单元格中显示文本时,若内容过多而导致换行或撑宽单元格,下面是我在网上找的一个解决方法,共享一下,希望对大家有用:

代码如下:

<table>

    <tr>

        <td>

            <div style=" 100px; height: 18px; border: 0px;overflow:hidden; padding:3px 2px 0px 2px; text-overflow:ellipsis">

                <nobr title='这里放置要显示的文本'>

                     这里放置要显示的文本

                </nobr>

            </div>

        </td>

    </tr>

</table>

效果如下:

  

 

若在GridView的绑定列中可使用以下方式:

<asp:TemplateField HeaderText="显示列名">

    <ItemStyle Width="130px" />

    <ItemTemplate>

        <div style=" 100px; height: 18px; border: 0px;overflow:hidden; padding:3px 2px 0px 2px; text-overflow:ellipsis">

            <nobr title='<%#Eval("绑定列名")%>'>

                <%#Eval("绑定列名")%>

            </nobr>

        </div>

    </ItemTemplate>

</asp:TemplateField>

原文地址:https://www.cnblogs.com/linyechengwei/p/1620985.html