2011-05-26 36 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表格呈現的。 在表格中,包含的內容總是獲勝。如果列內的文本大於您聲明的內容,則該列將被展開。

相關問題