c# - 使用 CSS 设置 GridView 格式

标签 c# asp.net .net css

我有一个页面,附有该图像。 在我的CSS中,我配置宽度和高度以自动显示表格! 但在某些列中,例如,不会显示一行中的所有信息。 如何配置网格以在一行中显示所有行?

我的aspx:

<body>
<form id="form1" runat="server">
<div>
    <div style="width: auto; height: auto;" align="center">
        <img src="image/NdriveBanner.png" align="center" />
    </div>
    <br />
    <br />
    <div id="Div1" runat="server">
        <asp:Label Font-Bold="true" runat="server" Font-Size="X-Large">Here are your tickets!</asp:Label>
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" GridLines="None"
            CssClass="table table-bordered table-striped">
            <Columns>
                <asp:BoundField DataField="UserName" HeaderText="User" />
                <asp:BoundField DataField="AccessGroup" HeaderText="Access Group" />
                <asp:BoundField DataField="FolderAccess" HeaderText="Folder Access" />
                <asp:BoundField DataField="RequestDate" HeaderText="Request Date" DataFormatString="{0:d}" />
                <asp:BoundField DataField="SituationDesc" HeaderText="Situation" />
                <asp:BoundField DataField="Approver" HeaderText="Approver" />
                <asp:BoundField DataField="ApprovalDate" HeaderText="Approval Date" DataFormatString="{0:d}" />
                <asp:BoundField DataField="BusinessJustification" HeaderText="Business Justification" />
                <asp:BoundField DataField="Server" HeaderText="Server Name" />
                <asp:BoundField DataField="UserRequestor" HeaderText="User Request" />
                <asp:TemplateField Visible="false">
                    <ItemTemplate>
                        <asp:HiddenField ID="Access" runat="server" Value='<%# Bind("Access") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    <br />
    <br />
    <div align="center" style="width: auto; height: auto;">
        <asp:HyperLink ID="HyperLink2" runat="server" ImageUrl="~/image/home_back_48.png"
            NavigateUrl="~/home.aspx">homepage</asp:HyperLink>
    </div>
</div>
</form>

我的.css

table
{
    max-width:none;
    background-color:transparent;
    border-collapse:collapse;
    border-spacing:0;
}

.table
{
    width:auto;
    height:auto;
    margin-bottom:20px;
}

.table th,.table td
{
    width:auto;
    height:auto;
    padding:8px;
    line-height:20px;
    text-align:left;
    vertical-align:top;
    border-top:1px solid #dddddd;
}

.table th
{
    width:auto;
    height:auto;
    font-weight:bold;
}

.table thead th
{
    vertical-align:bottom;
}

enter image description here

最佳答案

尝试将 white-space: no-wrap; 添加到您的 .table th,.table td 规则中。如果它有效,您将获得一些大单元格,并且需要水平滚动页面才能看到所有内容,这从来都不是有趣的。

关于c# - 使用 CSS 设置 GridView 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17792424/

相关文章:

c# - 在 Silverlight 4 中下载后自动打开文件

asp.net - 在 session 变量中放入什么

asp.net - ASP.NET 商业 Uber-Grids 的开源替代方案

c# - 如何将组框锚定到左侧但允许组框在拉伸(stretch)时增长到最大宽度

c# - HttpWebRequest、C# 和 Https

c# - 如何从父组件中的事件更新子组件属性

asp.net - RegularExpressionValidator 限制输入长度而不限制字符类型

c# - 在 .NET winform 中重现表格模型

c# - FindResource 无法与位图一起使用

c# - 在未安装 Outlook 客户端的情况下使用 Microsoft.Office.Interop.Outlook