简体   繁体   English

GridView中的列宽

[英]Column width in gridview

So I have tried to define the width of the template field in 7 places ( ControlStyle-Width , ItemStyle-Width , HeaderStyle-Width , ControlStyle Width , ItemStyle Width , TextBox Width and finally in a css ), but it still wraps the content ("1400 kr"). 所以我尝试在7个地方定义模板字段ControlStyle-WidthControlStyle-WidthItemStyle-WidthHeaderStyle-WidthControlStyle WidthItemStyle WidthTextBox Width ,最后是css ),但是它仍然包裹了内容( “ 1400 kr”)。 What is the matter here? 这是怎么回事

               <asp:TemplateField HeaderText="Totalt" ControlStyle-Width="100" ItemStyle-Width="100" ItemStyle-Wrap="True" HeaderStyle-Width="100" ControlStyle-CssClass="wide">
                  <ItemTemplate>
                        <asp:TextBox ID="tbTotalPrice" runat = server ReadOnly="true" Width="100px"></asp:TextBox>               
                    </ItemTemplate>
                    <ControlStyle Width="100px" />
                    <ItemStyle HorizontalAlign="Right" Width="100px" />
                </asp:TemplateField>

the style sheet: 样式表:

.wide {
    width: 120px;
    column-width: 120px;
}

Make sure that you didn't give the total width of the Gridview. 确保您没有提供Gridview的总宽度。 If you had given total width of the Gridview then remove it. 如果已给出Gridview的总宽度,则将其删除。

Also there is no need to give class for Item Template as you had already defined the manual column width. 另外,由于您已经定义了手动列宽,因此无需为“项模板”提供类。

use column tags instead of ItemTemplate tags and then set column width. 使用列标签代替ItemTemplate标签,然后设置列宽。 you also can use style="white-space: nowrap;overflow: hidden;" 您还可以使用style =“ white-space:nowrap; overflow:hidden;” which will truncate the text if it is larger than column width. 如果它大于列宽,它将截断文本。 You can use style="overflow: hidden;" 您可以使用style =“ overflow:hidden;” if you want your text to be wrapped. 如果您希望将文本换行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM