网格视图边界的宽度

时间:2011-06-21 05:39:17

标签: asp.net gridview boundfield

我无法设置绑定字段的宽度。以下标记中是否有任何问题。

 <asp:BoundField DataField="UserName" HeaderText="User Name"
                   meta:resourcekey="BoundFieldUNCUserNameResource1">
        <HeaderStyle Width="50%" />
 </asp:BoundField>

enter image description here

请参阅图片。我使用以下设置宽度。黄色数字对应宽度。标记的用户名始终为Wrapped,即使我将宽度设置为较大的值(例如50%)并设置Wrap =“false”。

<HeaderStyle Width="20%" Wrap="true" />
<ItemStyle Width="20%" Wrap="true" />

6 个答案:

答案 0 :(得分:34)

试试这个:

BoundField标记中的

ItemStyle-Width="50%" ItemStyle-Wrap="false"

答案 1 :(得分:6)

对于BoundField:

 <asp:BoundField DataField="UserName" HeaderText="User Name" ItemStyle-Width="50px" />

答案 2 :(得分:1)

令人惊讶的是,即使是现在,在2016年,ItemStyle-WidthHeaderStyle-Width属性通常会在ASP.Net GridView控件中被忽略。

有时,他们似乎没有创造任何标记。

我的解决方案是放弃尝试设置此属性,而是使用普通的旧CSS:

.AspNet-GridView table tbody tr td:nth-child(1)
{
    /*  Set the width of the 1st GridView column */
    width: 200px;
}
.AspNet-GridView table tbody tr td:nth-child(2)
{
    /*  Set the width of the 2nd GridView column */
    width: 300px;
}

答案 3 :(得分:0)

我今天也面临这个问题。我得到的是你必须在css类中定义你的宽度&amp;称为boundfeild中的css类。 e.g。

HeaderStyle-CssClass="width350"

答案 4 :(得分:0)

要更改列宽gridview边界域,只需在边界域内添加

ItemStyle-Width="200"  ItemStyle-Wrap="False"

对我有用,请尝试

答案 5 :(得分:0)

尝试了几种没有运气的解决方案后,我能够向该项目添加一个CSS类。似乎需要设置HeaderStyle-CssClass和ItemStyle-CssClass属性:

    <asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-CssClass="Name" ItemStyle-CssClass="Name" />
相关问题