开发者

how to make a column width size fixed in datagridview asp?

开发者 https://www.devze.com 2023-02-02 04:55 出处:网络
i have this column in a datagridview on aspx page <asp:TemplateField HeaderText=\"Observacion\">

i have this column in a datagridview on aspx page

<asp:TemplateField HeaderText="Observacion">
    <ItemTemplate>
        <asp:Label ID="lblOrderID" runat="server" Text='<%# Eval("Observacion") %>'></asp:Label>
    </ItemTemplate>
    <ItemStyle Width="200px" Wrap="False" />
</asp:TemplateField>

I have set up the itemstyle with and wrap to false, but开发者_开发技巧 anyways the width columns grows the the data is too long. i just want to change the height of the column not the width. Here us the complete code of the datagridview

<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" CellPadding="4" EnableModelValidation="True" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False">
    <columns>
        <asp:boundfield datafield="ID_OBSERVACION" visible="False" />
        <asp:boundfield datafield="AUTOR" headertext="Autor" />
        <asp:boundfield datafield="FECHA" headertext="Fecha" />

        <asp:TemplateField HeaderText="Observacion">
        <ItemTemplate>
            <asp:Label ID="lblOrderID" runat="server" Text='<%# Eval("Observacion") %>'></asp:Label>
        </ItemTemplate>
        <ItemStyle Width="200px" Wrap="False" />
        </asp:TemplateField>

    </columns>

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" Wrap="False" />
    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" Wrap="False" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>


Apparently, the Width parameter is not compatible with the Wrap parameter. Without Width, the Wrap=False part is accepted.


Wrap should be set to true so that the browser can wrap the cell contents. However if a single word within the cell is wider than the cell width, the browser would not break it. If that is the case, you may have to use the table-layout: fixed along with column width.

0

精彩评论

暂无评论...
验证码 换一张
取 消