如何设置Gridview BoundField Column的最大宽度?

时间:2011-05-26 17:04:02

标签: gridview width max boundfield

我有一个设计缺陷,迫切需要帮助,因为我对.NET很新。

我的页面上有一个GridView,我的目标是限制每列的最大宽度。以下是代码:

<asp:GridView ID="GridViewMessages" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID" DataSourceID="LinqDataSourceMessages"
        ForeColor="#333333" GridLines="None" Width="600px">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:CommandField ShowDeleteButton="true" ButtonType="Button" ControlStyle-BackColor="Red" />
            <asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
            <asp:BoundField DataField="FromUser" HeaderText="Pengirim" InsertVisible="False"
                ReadOnly="True" SortExpression="FromUser" ItemStyle-Width="10%" ItemStyle-Wrap="false" />
            <asp:BoundField DataField="ToUser" HeaderText="Penerima" InsertVisible="False" ReadOnly="True"
                SortExpression="ToUser" ItemStyle-Width="10%" ItemStyle-Wrap="false" />
            <asp:BoundField DataField="Message1" HeaderText="Pesan" InsertVisible="False" ReadOnly="True"
                SortExpression="Message1" HeaderStyle-Width="50%" HeaderStyle-Wrap="false" ItemStyle-Width="50%" ItemStyle-Wrap="false" />
            <asp:CheckBoxField DataField="IsDone" HeaderText="Selesai?" SortExpression="IsDone"
                ReadOnly="false" ItemStyle-Width="10%" ItemStyle-Wrap="false" />
            <asp:BoundField DataField="DateCreated" HeaderText="Tanggal Buat" InsertVisible="False"
                ReadOnly="True" SortExpression="DateCreated" ItemStyle-Width="20%" ItemStyle-Wrap="false" />
        </Columns>
        <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" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>

即使我使用ItemStyle-Width="300px",如果数据的长度大于300px,它也无效。只有当每个数据的长度小于设定宽度时,一切似乎都有效。

你们知道我怎么能改变这个设计问题?

提前非常感谢你。

1 个答案:

答案 0 :(得分:0)

我想这是因为网格是用HTML表格渲染的。 在一个表中,包含总是获胜。如果列中的文本大于您声明的内容,则该列将被展开。

相关问题