GridView 自动折行的解决方案

当GridView 行内文字过长,且文字内有数字,字母或者符号的时候,会出现汉字和字母数字中间折行,很不美观,经过几番测试,终于找到一个比较完美的解决方案。

设置设备名称列

  <ItemStyle HorizontalAlign="Center"  Width="100px" Wrap="true" />

前台页面代码:

<asp:GridView ID="gvAllocate" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# (this.pager.CurrentPageIndex - 1) * this.pager.PageSize + Container.DataItemIndex + 1%>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="50px" />
</asp:TemplateField>
<asp:BoundField DataField="AINFO_NO" HeaderText="调拨编号">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="EQUIP_INFO_NAME" HeaderText="设备名称">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="100px" Wrap="true" />
</asp:BoundField>
<asp:BoundField DataField="EQUIP_INFO_MODEL" HeaderText="规格型号">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="TYPE_NAME" HeaderText="设备类型">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="ALIST_NUM" HeaderText="调拨数量">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="AINFO_TIME" HeaderText="调拨时间" DataFormatString="{0:yyyy-MM-dd}">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="AINFO_USER" HeaderText="调拨人">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="60px" />
</asp:BoundField>
</Columns>
</asp:GridView>

CS代码:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//自动换行
gvAllocate.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
}
}
posted @ 2011-06-17 10:05  灵雨飘零  阅读(2374)  评论(3编辑  收藏  举报