2011-05-26 39 views
1

我有一个设计缺陷,迫切需要帮助,因为我对.NET相当新。如何设置Gridview的BouldField列的最大宽度?

我的页面上有一个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",如果数据的长度大于300像素更大,它不会工作。一切似乎只有在每个数据的长度小于设定宽度时才起作用。

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

非常感谢你提前。

回答

0

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

相关问题