问题
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