首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何设置Gridview的BouldField列的最大宽度?

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

Stack Overflow用户
提问于 2011-05-27 01:04:02
回答 1查看 2K关注 0票数 2

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

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

代码语言:javascript
运行
复制
<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,它也不会工作。只有当每个数据的长度小于设置的宽度时,一切似乎才能正常工作。

你们知道怎样才能改变这个设计问题吗?

非常感谢你提前这么做。

EN

回答 1

Stack Overflow用户

发布于 2011-07-28 17:05:30

我想这是因为网格是用HTML表格呈现的。在表中,包含的始终是赢家。如果列中的文本比声明的文本大,则该列将被展开。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6142316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档