【问题标题】:GridView Column Sizes not Changing ASP.NETGridView 列大小不改变 ASP.NET
【发布时间】:2015-07-09 15:44:25
【问题描述】:

我正在尝试增加我的 gridview 中的一列的大小,但是,无论我如何尝试增加大小,列宽都无法增加。 GridView 的数据正在我的 c# 代码中检索,该代码从我的数据库中获取数据。我检查了gridview类的css代码,似乎没有任何东西影响列的宽度(或者至少我认为)。为什么我的列宽不改变?

这是我目前的设置: ASP.NET:

 <div id="grid" style="overflow-x: auto; margin: auto; min-width: 100%; min-height: 100px; text-align: center;">
            <asp:Label runat="server" ID="empty" Font-Size="15px" Font-Bold="True" Visible="false"></asp:Label>
            <asp:GridView runat="server" ID="lessonsgrid" CssClass="gridview" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField ItemStyle-Width="1%" HeaderText="Id" SortExpression="Id" DataField="Id" />
                    <asp:BoundField ItemStyle-Width="10%" HeaderText="Release" SortExpression="Release" DataField="Release" />
                    <asp:BoundField ItemStyle-Width="10%" HeaderText="Category" SortExpression="Category" DataField="Category" />
                    <asp:BoundField ItemStyle-Width="10%"  HeaderText="Subcategory" SortExpression="Subcategory" DataField="Subcategory" />
                    <asp:BoundField ItemStyle-Width="20%" ItemStyle-CssClass="descriptionCol" ItemStyle-HorizontalAlign="Left" HeaderText="Description" SortExpression="Description" DataField="Description" />
                    <asp:BoundField ItemStyle-Width="10%"  HeaderText="Identifying Team" SortExpression="Identifying Team" DataField="Identifying Team" />
                    <asp:BoundField ItemStyle-Width="5%"  HeaderText="Name" SortExpression="Name" DataField="Name" />
                    <asp:BoundField ItemStyle-Width="10%"  ItemStyle-HorizontalAlign="Left" HeaderText="Suggestions For Improvement" SortExpression="Suggestions For Improvement" DataField="Suggestions For Improvement" />
                    <asp:BoundField ItemStyle-Width="5%"  HeaderText="Team Assigned To" SortExpression="Team Assigned To" DataField="Team Assigned To" />
                    <asp:BoundField ItemStyle-Width="5%"  HeaderText="Implemented" SortExpression="Implemented" DataField="Implemented" />
                    <asp:BoundField ItemStyle-Width="5%"  HeaderText="Priority" SortExpression="Priority" DataField="Priority" />
                    <asp:BoundField ItemStyle-Width="5%"  HeaderText="Implement Complexity" SortExpression="Implement Complexity" DataField="Implement Complexity" />
                    <asp:BoundField ItemStyle-Width="10%"  HeaderText="Target Implement Date" SortExpression="Target Implement Date" DataField="Target Implement Date" />
                    <asp:BoundField ItemStyle-Width="10%"  ItemStyle-HorizontalAlign="Left" HeaderText="Comment" SortExpression="Comment" DataField="Comment" />
                </Columns>
            </asp:GridView>
        </div>

CSS .gridview:

.gridview a:link {
    color: #0043bd;
    font-weight: bold;
    text-decoration: none;
}

.gridview a:visited {
    color: #0043bd;
    font-weight: bold;
    text-decoration: none;
}

.gridview a:active,
.gridview a:hover {
    color: #bd5a35;
    text-decoration: underline;
}

.gridview {
    font-family: Arial, Helvetica, sans-serif;
    color: #666;
    font-size: 12px;
    text-shadow: 1px 1px 0px #fff;
    background: #eaebec;
    margin: 20px;
    border: #ccc 1px solid;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;
    -moz-box-shadow: 0 1px 2px #d1d1d1;
    -webkit-box-shadow: 0 1px 2px #d1d1d1;
    box-shadow: 0 1px 2px #d1d1d1;
}

    .gridview th {
        padding: 10px 25px 10px 25px;
        border-top: 1px solid #e0e0e0;
        border-bottom: 1px solid #e0e0e0;
        background: #ededed;
        background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#ebebeb));
        background: -moz-linear-gradient(top, #ededed, #ebebeb);
    }

        .gridview th:first-child {
            text-align: left;
            padding-left: 20px;
        }

    .gridview tr:first-child th:first-child {
        -moz-border-radius-topleft: 3px;
        -webkit-border-top-left-radius: 3px;
        border-top-left-radius: 3px;
    }

    .gridview tr:first-child th:last-child {
        -moz-border-radius-topright: 3px;
        -webkit-border-top-right-radius: 3px;
        border-top-right-radius: 3px;
    }

    .gridview tr {
        text-align: center;
        padding-left: 20px;
    }

    .gridview td:first-child {
        text-align: left;
        padding-left: 20px;
        border-left: 0;
    }

    .gridview td {
        padding: 10px;
        border-top: 1px solid #ffffff;
        border-bottom: 1px solid #e0e0e0;
        border-left: 1px solid #e0e0e0;
        background: #fafafa;
        background: -webkit-gradient(linear, left top, left bottom, from(#fbfbfb), to(#fafafa));
        background: -moz-linear-gradient(top, #fbfbfb, #fafafa);
    }

    .gridview tr.even td {
        background: #f6f6f6;
        background: -webkit-gradient(linear, left top, left bottom, from(#f8f8f8), to(#f6f6f6));
        background: -moz-linear-gradient(top, #f8f8f8, #f6f6f6);
    }

    .gridview tr:last-child td {
        border-bottom: 0;
    }

        .gridview tr:last-child td:first-child {
            -moz-border-radius-bottomleft: 3px;
            -webkit-border-bottom-left-radius: 3px;
            border-bottom-left-radius: 3px;
        }

        .gridview tr:last-child td:last-child {
            -moz-border-radius-bottomright: 3px;
            -webkit-border-bottom-right-radius: 3px;
            border-bottom-right-radius: 3px;
        }

    .gridview tr:hover td {
        background: #f2f2f2;
        background: -webkit-gradient(linear, left top, left bottom, from(#f2f2f2), to(#f0f0f0));
        background: -moz-linear-gradient(top, #f2f2f2, #f0f0f0);
    }

【问题讨论】:

  • 一栏有204%。
  • 是的,那是我想看看是否会有任何变化,不幸的是没有。
  • 如果表格内容太多,列会变得太紧,他们将无法应用您指定的宽度。

标签: c# html css asp.net gridview


【解决方案1】:

很遗憾,我还不能添加评论,但您正在对所有元素使用百分比。需要有一个具有实际固定宽度的元素。这样,百分比就知道要占用该宽度的百分比。

【讨论】:

  • 我将 id 列更改为 50px,但没有任何反应。
  • 看看是否将 div id="grid" 上的宽度设置为 800px 之类的东西。
  • 没什么,我将 div 设置为 1000px,但列宽没有任何变化。
  • 刚刚注意到我没有在您的网格视图本身上看到任何宽度属性。 !00% 或固定值。
  • 我将 gridview 宽度设置为 100%,我尝试了 1060px。但这也没有效果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 2010-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多