我一直在寻找这个问题的答案,但没有找到我要找的东西。我有一个包含 5 列的 GridView。其中一列是一个很长的字符串,用“”代替。我需要能够固定列的宽度并让自动换行处理字符串直到它的末尾。我已经尝试了 gridview 上的所有属性来获得我需要的东西,但跨度总是水平拉伸(stretch)并且从不换行。这是我的 gridView 代码
<asp:GridView ID="resultsGrid" AutoGenerateColumns="False" runat="server" AllowPaging="True"
AllowSorting="True" PageSize="20" OnPageIndexChanging="gridView_PageIndexChanging"
OnSorting="gridView_Sorting" PagerSettings-Position="TopAndBottom" PagerStyle-HorizontalAlign="Center">
<PagerSettings Position="TopAndBottom" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Container.DataItemIndex + 1 + "." %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false" SortExpression="record_id">
<ItemTemplate>
<asp:Label ID="lblRecordID" runat="server" Text='<%# Bind("RecordID") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Note Type" SortExpression="business_content_type_cd">
<ItemTemplate>
<asp:Label ID="lblNoteType" runat="server" Text='<%# Bind("NoteType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Author" SortExpression="author_user_name">
<ItemTemplate>
<asp:Label ID="lblAuthor" runat="server" Text='<%# Bind("Author") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="content_dttm">
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label Width="100px" ID="lblData" runat="server" Text='<%# Bind("NoteContent") %>'></asp:Label>
<asp:HyperLink ID="linkMore" runat="server" />
</ItemTemplate>
<FooterStyle Wrap="true" Width="100px" />
<HeaderStyle Wrap="true" Width="100px" />
<ItemStyle Wrap="true" Width="100px" />
</asp:TemplateField>
<asp:TemplateField SortExpression="size" Visible="false">
<ItemTemplate>
<asp:Label ID="lblSize" runat="server" Text='<%# Bind("Size") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
我不喜欢我必须做的事情,但客户想要客户想要的东西(我需要模仿大型机屏幕的用户界面)。感谢您的帮助
最佳答案
已使用 white-space: normal;
用于它们之间有空格的字符串
word-break: break-all
用于类似连接的字符串。
并在文档准备好的表格布局中为网格添加 css 样式:固定在网格样式中对我有用
<asp:TemplateField HeaderText="Action">
<ItemStyle Wrap="true"/>
<ItemTemplate>
<div style="white-space: normal; word-break: break-all;">
<asp:Label ID="lblLogStatus" runat="server" Text='<%# Eval("LogMsg")%>' Style="white-space: normal !important; word-break: break-all !important;"></asp:Label>
</div> </ItemTemplate>
</asp:TemplateField>
关于.net - 使用自动换行修复 Gridview 列的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5412172/