2012-10-11 41 views
0

我身邊這方面的工作得到一個解決方案,網格視圖大小隨數據大小而變化?

> <asp:GridView ID="GridView1" runat="server" EnableViewState="False" 
> BorderWidth="1" 
>      HorizontalAlign="Left" HeaderStyle-BackColor="#5c7990" CellPadding="4" ForeColor="#333333" 
>      AutoGenerateColumns="false" GridLines="None" DataKeyNames="ID" AutoGenerateDeleteButton="false" 
>      EmptyDataText="No records found" CssClass="GridView123" Width="90%" 
>      OnRowCreated="GridView1_RowCreated"> 
>      <HeaderStyle CssClass="GridHeader" /> 
>      <FooterStyle CssClass="GridFooter" /> 
>      <RowStyle CssClass="RowStyle" VerticalAlign="Top" Wrap="true" /> 
>      <AlternatingRowStyle CssClass="AlternateRowStyle" VerticalAlign="Top" Wrap="true" /> 
>      <Columns> 
>       <asp:BoundField DataField="ID" HeaderText="ID" ItemStyle-Width="20%"> 
>        <ItemStyle Width="20%"></ItemStyle> 
>       </asp:BoundField>       
>       <asp:TemplateField HeaderText="Name" ItemStyle-Width="100%" ItemStyle-Wrap="true"> 
>        <ItemTemplate> 
>         <span id="PName<%# Eval("ID") %>"> 
>          <%# Eval("Name") %></span> 
>        </ItemTemplate> 
>        <ItemStyle Wrap="True" Width="100%"></ItemStyle> 
>       </asp:TemplateField> 
> 
> </columns> 
<asp:GridView> 

這是我網格視圖。我的問題是gridview的寬度正在改變不同的數據。當列中有大量數據時,它正在擴展,當列填充小數據時,它正在縮小。

我已經申請包裹的東西列太

我想有這將始終如一地顯示在獨特的尺寸什麼都該數據填充網格視圖。

感謝您的幫助...

+0

請檢查這個URL。這會幫助你。 http://stackoverflow.com/questions/7789765/set-the-fix-column-width-in-gridview-and-if-content-is-bigger-than-the-column-wi – ravidev

回答

0

<asp:GridView ...的寬度從Width="90%"設置爲Width="640",這使得它成爲640像素的標準寬度。

要強制文本翹曲而不會增長,您還需要不要將ItemStyle-Wrap設置爲true,並且不要使用ether,否則請將其設置爲false。

ItemStyle-Wrap="false"

0

你有很多冗餘的寬度屬性。您不需要在BoundField和ItemStyle中爲同一列聲明它。然而,我相信你遇到問題的原因是因爲你正在設置一個120%的。

我在使用HTML的無數個小時中發現的情況是,在表列上使用百分比寬度時,不要超過100%,並始終保留1列,而不是寬度。即使你把所有的列加起來達到100%的寬度,我也會看到表格有點奇怪。我通常在除了「主」列之外的所有區域上定義寬度,並讓剩餘的寬度。

相關問題