如何设置Gridview的BouldField列的最大宽度?

如何设置Gridview的BouldField列的最大宽度?,gridview,width,max,boundfield,Gridview,Width,Max,Boundfield,我有一个设计缺陷,迫切需要帮助,因为我对.NET相当陌生 我的页面上有一个GridView,我的目标是限制每列的最大宽度。代码如下: <asp:GridView ID="GridViewMessages" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID" DataSourceID="LinqDa

我有一个设计缺陷,迫切需要帮助,因为我对.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,它也不会工作。只有当每个数据的长度小于设置的宽度时,一切似乎都能正常工作

你们知道我如何改变这个设计问题吗


提前非常感谢。

我想这是因为网格是用HTML表呈现的。
在一张桌子上,被包含的总是赢的。如果列中的文本大于您声明的文本,则列将被展开。

我想这是因为网格是用HTML表呈现的。 在一张桌子上,被包含的总是赢的。如果列中的文本大于您声明的文本,则该列将展开