3

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

Tomas
  • 17,551
  • 43
  • 152
  • 257

3 Answers3

6

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>
Tomas
  • 17,551
  • 43
  • 152
  • 257
5
 <asp:BoundField DataField="DataField" HeaderText="HeaderText"  ItemStyle-  CssClass="breakword" />
 .breakword
 {
 word-wrap:break-word;
 word-break:break-all;
 }
Boriss Pavlovs
  • 1,441
  • 12
  • 8
1

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

Community
  • 1
  • 1
Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54