One of BoundField in my GridView has very long string without spaces and it resize GridView. How to break long strings in GridView columns?
Asked
Active
Viewed 8,931 times
3 Answers
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
-
don't you have the possibility to restrict text size with "text(...)" and display all text in a tooltip? – lnu Dec 21 '11 at 10:33
-
Been looking everywere for this. – Kieran Quinn Oct 10 '14 at 11:17
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
-
The biggest problem of your solution is that Text is hidden, I would like to break it to next line and show it fully to user. – Tomas Dec 21 '11 at 09:45
-