2011-06-21 80 views
14

我无法设置绑定域的宽度。在下面的标记中是否有任何问题。网格视图绑定域的宽度

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

enter image description here

请参考图片。我使用以下设置宽度。黄色的数字是相应的宽度。即使我将宽度设置为较大的值(比如50%)并将Wrap设置为“false”,标记的用户名始终是包裹的。在绑定列标签

回答

27

尝试这个

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

当Wrap =“false”时ItemStyle-Width =“120px”无效。为什么? – ZahidKakar

+0

这似乎对asp:GridView没有影响。 – ebyrob

6

ItemStyle-Width="50%" ItemStyle-Wrap="false"对于绑定列:

<HeaderStyle Width="20%" Wrap="true" /> 
<ItemStyle Width="20%" Wrap="true" /> 
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; 
} 
0

我今天也面临这样的问题。我得到的是你必须在css类&中定义ur宽度,在boundfeild中调用该css类。 例如

HeaderStyle-CssClass="width350"