如何在Pageload上显示Gridview标头?

时间:2016-08-31 12:02:25

标签: asp.net

我可以帮助您在加载页面时如何显示gridview的标题。在我的aspx页面中。提前致谢

<asp:GridView ID="grvProductInventory" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" class="table-responsive table table-striped jambo_table bulk_action" CellPadding="4" ForeColor="#333333" GridLines="None">
                        <EditRowStyle BackColor="#999999" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <Columns>
                            <asp:CommandField ShowDeleteButton="True" DeleteText="Remove" />
                            <asp:BoundField HeaderText="Seller" DataField="pSeller"/>
                            <asp:BoundField HeaderText="Buyer " DataField="pBuyer"/>
                            <asp:BoundField HeaderText="QTY" DataField="pQTY" DataFormatString="{0:#,###0.000}"/>
                            <asp:BoundField HeaderText="Code" DataField="pCode" />
                            <asp:BoundField HeaderText="Product" DataField="pProduct" />
                            <asp:BoundField HeaderText="Date From" DataField="Date1" DataFormatString ="{0:dd/M/yyyy}" />
                            <asp:BoundField HeaderText="Date To" DataField="Date2" DataFormatString ="{0:dd/M/yyyy}" />
                            <asp:BoundField HeaderText="Total Days" DataField="TotalDays" />
                            <asp:BoundField HeaderText="Pur Prem" DataField="pPurPremium" />
                            <asp:BoundField HeaderText="Ave" DataField="Ave" DataFormatString="{0:#,###0.000}"/>
                            <asp:BoundField HeaderText="Net Price" DataField="NetPurPrice" DataFormatString="{0:#,###0.000}"/>
                            <asp:BoundField HeaderText="USD" DataField="USD" DataFormatString="{0:#,###0.000}"/>
                            <asp:BoundField HeaderText="AED" DataField="AED" DataFormatString="{0:#,###0.000}"/>
                        </Columns>
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    </asp:GridView>

2 个答案:

答案 0 :(得分:3)

you can bind gridview with blank dataset or datatable. Then show only gridview column.

答案 1 :(得分:2)

设置网格视图的属性ShowHeaderWhenEmpty =&#34; true&#34;。 然后  将空数据集或数据表绑定到gridview。

GridView1.DataSource = dt;         GridView1.DataBind();