GridView变量具有RowCount = 0设置EnableViewState = False for Gridview on Button Click

时间:2013-08-06 21:58:26

标签: vb.net gridview viewstate rows

我有一个asp:GridView和一个数据源,它从中提取了数千条记录。我启用了分页以使页面运行得更快。我有一个删除分页的按钮,同时将gridview和datasource的ViewState设置为false。如果我没有为gridview,数据源或两者设置ViewState为false,则浏览器会抛出错误,甚至不会到达服务器端代码。我99%肯定这是因为ViewState太大了。

问题在于,当我单击按钮导出所有行时,后面的服务器端代码将gridview显示为零行。我不确定是否需要在没有ViewState的情况下找到重新绑定数据的方法,或者修复是否简单。

Protected Sub btnPaging_Click(sender As Object, e As System.EventArgs) Handles btnPaging.Click
    If btnPaging.Text = "VIEW ALL - REMOVE PAGING" Then
        GRIDVIEW.AllowPaging = False
        GRIDVIEW.EnableViewState = False
        'DATASOURCE.EnableViewState = False
        btnPaging.Text = "VIEW FEWER - ADD PAGING"
    Else
        GRIDVIEW.AllowPaging = True
        GRIDVIEW.EnableViewState = True
        'DATASOURCE.EnableViewState = True
        btnPaging.Text = "VIEW ALL - REMOVE PAGING"
    End If
End Sub

<asp:GridView ID="GRIDVIEW" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="DATASOURCE"
                    GridLines="None" CssClass="gridView" ShowFooter="True" EnableViewState="True" AllowPaging="true" PageSize="500">
            <PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" PageButtonCount="15" Position="TopAndBottom" />
            <PagerStyle Font-Size="1.8em" />
            <FooterStyle CssClass="footer" />
            <RowStyle CssClass="row" />
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox runat="server" ID="cbRow" CssClass="checkbox" />
                    </ItemTemplate>
                    <HeaderTemplate>
                        <asp:CheckBox ID="cbAll" runat="server" />
                    </HeaderTemplate>
                </asp:TemplateField>

                <asp:BoundField DataField="DATE" HeaderText="BILL DT" SortExpression="DATE" />
                <asp:BoundField DataField="DATE2" HeaderText="PU DT" SortExpression="DATE2" />
                <asp:BoundField DataField="CUSTNAME" HeaderText="SHIPPER" SortExpression="CUSTNAME" />
                <asp:BoundField DataField="CUSTNAME2" HeaderText="CONSIGNEE" SortExpression="CUSTNAME2" />
                <asp:BoundField DataField="OPNAMT" HeaderText="DUE $" SortExpression="OPNAMT" DataFormatString="{0:n2}">
                    <HeaderStyle HorizontalAlign="Right" />
                    <ItemStyle HorizontalAlign="Right" />
                </asp:BoundField>
                <asp:BoundField DataField="PC" HeaderText="P" SortExpression="PC" />
                <asp:BoundField DataField="STMTNUM" HeaderText="STMT #" SortExpression="STMTNUM" />
                <asp:BoundField DataField="STMTDATE" HeaderText="DATE" SortExpression="STMTDATE" />
                <asp:BoundField DataField="BL" HeaderText="BL#" SortExpression="BL" />
                <asp:BoundField DataField="PO" HeaderText="PO#" SortExpression="PO" />
                <asp:BoundField DataField="REF" HeaderText="REF#" SortExpression="REF" />
                <asp:BoundField DataField="TOTAR" HeaderText="TOTAR" DataFormatString="{0:n2}" SortExpression="TOTAR" />

            </Columns>
            <HeaderStyle CssClass="header" />
            <AlternatingRowStyle CssClass="alternatingRow" />
        </asp:GridView>

0 个答案:

没有答案