GridView BoundField break long string

别来无恙 提交于 2019-12-20 15:24:05

问题


One of BoundField in my GridView has very long string without spaces and it resize GridView. How to break long strings in GridView columns?


回答1:


I have found the solution which works in my situation

 <asp:TemplateField ItemStyle-Width="350px" HeaderText="Source">
        <ItemTemplate>
            <div style="width: 350px;word-wrap:break-word; ">
                <%# Eval("Source")%>
            </div>
        </ItemTemplate>
    </asp:TemplateField>



回答2:


 <asp:BoundField DataField="DataField" HeaderText="HeaderText"  ItemStyle-  CssClass="breakword" />
 .breakword
 {
 word-wrap:break-word;
 word-break:break-all;
 }



回答3:


You may have a look at this question Setting width of bound column

Anyway a quick solution for your problem will make use of a template field and using word-wrap attribute.

<asp:TemplateField HeaderText="Name (short)">
     <ItemTemplate>
          <div style="width: 40px; word-wrap: break-word;">
               <%# Eval("Name") %>
           </div>
      </ItemTemplate>
</asp:TemplateField>

hth



来源:https://stackoverflow.com/questions/8587538/gridview-boundfield-break-long-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!