Asp.net 的 GridView 使用 table-layout:fixed 樣式 固定寬度

設置表格樣式style="table-layout:fixed;width:800px;",也就是GridView的樣式。

HeaderStyle:控制欄位的樣式,Gridview表頭的樣式。
ControlStyle:控制儲存內容控件的樣式,例如input標籤。
ItemStyle:通用樣式,這個就不常用到了。

範例說明(aspx)

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                CellPadding="4" DataKeyNames="MV001" DataSourceID="SqlDataSource1" 
                BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" Width="100%" style="table-layout:fixed;" >
                <Columns>
                    <asp:CommandField ShowEditButton="True" CancelText="☆" EditText="△" 
                        UpdateText="★" >
                    </asp:CommandField>
                    <asp:BoundField DataField="MV001" HeaderText="工號" ReadOnly="True" SortExpression="MV001">
                    <HeaderStyle Width="50px" />
                    <ItemStyle  width="50px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="NAME" HeaderText="姓名" SortExpression="NAME">
                    <HeaderStyle Width="60px" />
                    <ItemStyle  width="60px" />
                    <ControlStyle Width="60px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="MV004" HeaderText="ISO" SortExpression="MV004" >
                    <HeaderStyle Width="30px" />
                    <ItemStyle  width="30px" />
                    <ControlStyle Width="30px" />
                    </asp:BoundField>
<!-- 
######################################################################
######################################################################
######################################################################
-->
                </Columns>
                <EditRowStyle BackColor="#FFFF66" />
                <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" 
                    Width="50px" HorizontalAlign="Center" Wrap="True" />
                <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
                <RowStyle BackColor="White" ForeColor="#330099" HorizontalAlign="Center" 
                    Wrap="True" />
                <SelectedRowStyle Font-Bold="True" ForeColor="#663399" />
                <SortedAscendingCellStyle BackColor="#FEFCEB" />
                <SortedAscendingHeaderStyle BackColor="#AF0101" />
                <SortedDescendingCellStyle BackColor="#F6F0C0" />
                <SortedDescendingHeaderStyle BackColor="#7E0000" />
            </asp:GridView>

參考來源:DataGrid屬性

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s