.net - 使用自动换行修复 Gridview 列的宽度

标签 .net asp.net html css gridview

我一直在寻找这个问题的答案,但没有找到我要找的东西。我有一个包含 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/

相关文章:

javascript - Jquery 点击菜单可以工作,但在 Safari 和大多数移动浏览器中完全透明

.net - 显示 “you have crashed, we are sorry …”弹出窗口时完全停止应用程序

c# - .NET 4 任务类教程

c# - 使用ServiceStack和Signalr的Redis MQ

asp.net - 如何获取在 Asp.net 中与 $.post 一起发布的整个 JSon 文件

c# - 如何在您的 Asp.net 应用程序中获取最新的货币汇率

html - 背景图像:url();不工作

c# - 使用 Process.Start 时如何隐藏控制台应用程序用户界面?

c# - 如何使用 Razor 语法获取指向 ASP.NET MVC 4 文本中的 URL 的链接?

php - 如何 POST 从 PHP 创建的 HTML 表数据