【问题标题】:width of grid view boundfield网格视图边界的宽度
【发布时间】:2011-09-19 05:35:54
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: asp.net gridview boundfield


    【解决方案1】:

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

        <asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-CssClass="Name" ItemStyle-CssClass="Name" />
    

    【讨论】:

      【解决方案2】:

      要更改列宽 gridview boundfield 只需在 boundfield 内添加它

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

      它对我有用,试试这个

      【讨论】:

        【解决方案3】:

        我今天也面临这个问题。我得到的是你必须在 css 类中定义你的宽度并在 boundfeild 中调用那个 css 类。 例如

        HeaderStyle-CssClass="width350"
        

        【讨论】:

          【解决方案4】:

          令人惊讶的是,即使是现在,在 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;
          }
          

          【讨论】:

            【解决方案5】:

            对于BoundField:

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

            【讨论】:

              【解决方案6】:

              试试这个:

              BoundField 标签中的ItemStyle-Width="50%" ItemStyle-Wrap="false"

              【讨论】:

              • ItemStyle-Width="120px" 在 Wrap="false" 时无效。为什么?
              • 这似乎对 asp:GridView 没有影响。
              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-04-25
              • 2013-06-25
              • 1970-01-01
              • 1970-01-01
              • 2013-03-18
              • 1970-01-01
              相关资源
              最近更新 更多