Asp.net GridView在页脚下拉列表中设置页面大小

Asp.net GridView在页脚下拉列表中设置页面大小,asp.net,gridview,updatepanel,Asp.net,Gridview,Updatepanel,我在更新面板中有一个网格视图。在网格视图的页脚中,我有一个下拉列表,允许用户选择每页记录的数量。用户第一次使用下拉菜单选择页面大小时,它就起作用了。在此之后,下拉列表的selected index changed事件仅每隔一次激发一次。因此,奇数编号的下拉列表选择、选定索引更改激发、偶数编号的时间、选定索引更改不激发,下拉列表恢复为第一个选项,网格视图将加载该数量的记录 以下是标记: <asp:UpdatePanel runat="server" ID="UpdatePanel1">

我在更新面板中有一个网格视图。在网格视图的页脚中,我有一个下拉列表,允许用户选择每页记录的数量。用户第一次使用下拉菜单选择页面大小时,它就起作用了。在此之后,下拉列表的selected index changed事件仅每隔一次激发一次。因此,奇数编号的下拉列表选择、选定索引更改激发、偶数编号的时间、选定索引更改不激发,下拉列表恢复为第一个选项,网格视图将加载该数量的记录

以下是标记:

<asp:UpdatePanel runat="server" ID="UpdatePanel1">
        <ContentTemplate>
            <asp:ObjectDataSource ID="objectDataSourceResults" runat="server" SortParameterName="sortExpression">
                <SelectParameters>
                    <asp:Parameter Name="startIndex" Type="Int32" />
                    <asp:Parameter Name="pageSize" Type="Int32" />
                    <asp:Parameter Name="selectExpression" Type="String" />
                    <asp:Parameter Name="sortExpression" Type="String" />
                    <asp:Parameter Name="includeProperties" Type="String" />
                    <asp:Parameter Name="filterExpression" Type="String" />
                    <asp:Parameter Name="filterArray" Type="Object" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:GridView ID="gridResults" runat="server" AllowPaging="True" AllowSorting="True"  PageSize="25"
                EnableViewState="false" CssClass="Grid" EmptyDataRowStyle-CssClass="GridEmpty"
                ShowHeaderWhenEmpty="false" EmptyDataRowStyle-BorderStyle="None" DataSourceID="objectDataSourceResults"
                AutoGenerateColumns="False" EmptyDataText="No records returned">
                <EmptyDataTemplate>
                    <asp:Label ID="Label1" runat="server" Text="No records found" style="color:#FF0000"></asp:Label>
                </EmptyDataTemplate>
                <EmptyDataRowStyle CssClass="GridEmpty" />
                <AlternatingRowStyle CssClass="AltRow" />
                <SortedAscendingHeaderStyle CssClass="GridHeaderAscending" />
                <SortedDescendingHeaderStyle CssClass="GridHeaderDescending" />
                <PagerTemplate>
                    <table cellpadding="0" width="100%" cellspacing="0" class="GridPager">
                        <tr>
                            <td style="width: 30%; text-align: left; padding-left: 5px; padding-right: 5px">
                                <asp:ImageButton ID="buttonFirst" AlternateText="First Page" CommandArgument="0"
                                    Style="margin-top: 5px;" ImageUrl="~/controls/Images/grid_paging_first.ico" runat="server" />
                                <asp:ImageButton ID="buttonPrevious" AlternateText="" CommandArgument="prev" ImageUrl="~/controls/Images/grid_paging_previous.ico"
                                    runat="server" />
                                <asp:TextBox ID="SetPage" Width="27" MaxLength="3" AutoPostBack="true" runat="server" style="text-align:center;"
                                    CssClass="input-text"></asp:TextBox>
                                <asp:ImageButton ID="buttonNext" AlternateText="" CommandArgument="next" ImageUrl="~/controls/Images/grid_paging_next.ico"
                                    runat="server" />
                                <asp:ImageButton ID="buttonLast" AlternateText="Last Page" CommandArgument="last"
                                    ImageUrl="~/controls/Images/grid_paging_last.ico" runat="server" />
                            </td>
                            <td style="width: 20%; text-align: center;">
                                <asp:Label ID="Label2" runat="server" Text="Per Page:"></asp:Label>
                                <asp:DropDownList ID="dropDownRecordsPerPage" runat="server" CssClass="text-input" OnInit="dropDownRecordsPerPage_Init" 
                                    AutoPostBack="true" OnSelectedIndexChanged="dropDownRecordsPerPage_SelectedIndexChanged" AppendDataBoundItems="true"
                                    Style="text-align: right;">
                                    <asp:ListItem Value="10" Text="10" />
                                    <asp:ListItem Value="25" Text="25" />
                                    <asp:ListItem Value="50" Text="50" />
                                    <asp:ListItem Value="100" Text="100" />
                                    <asp:ListItem Value="1000" Text="All" />
                                </asp:DropDownList>
                            </td>
                            <td style="width: 20%; text-align: center;">
                                <asp:Label ID="labelPageCount" runat="server" />
                            </td>
                            <td style="width: 30%; text-align: right; padding-right: 5px;">
                                <asp:Label ID="labelRecordCount" runat="server" /><br />
                            </td>
                        </tr>
                    </table>
                </PagerTemplate>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>


不确定要包含哪些代码。我设置了下拉项:

''' <summary>
''' Create version to refernce in code
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub dropDownRecordsPerPage_Init(ByVal sender As Object, ByVal e As System.EventArgs)
    PageSizeDropDown = sender
    PageSizeDropDown.SelectedValue = gridResults.PageSize
End Sub 
“”
''创建代码中引用的版本
''' 
''' 
''' 
''' 
受保护的子dropDownRecordsPerPage_Init(ByVal发送方作为对象,ByVal e作为System.EventArgs)
PageSizeDropDown=发送方
PageSizeDropDown.SelectedValue=gridResults.PageSize
端接头
以及所选索引已更改事件:

 ''' <summary>
''' Reload the grid when results per page is changed
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Public Sub dropDownRecordsPerPage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    'Load the results
    gridResults.PageSize = PageSizeDropDown.SelectedValue
End Sub
“”
''更改每页的结果时重新加载网格
''' 
''' 
''' 
''' 
Public Sub-dropDownRecordsPerPage_SelectedIndexChanged(ByVal sender作为对象,ByVal e作为System.EventArgs)
'加载结果
gridResults.PageSize=PageSizeDropDown.SelectedValue
端接头

我必须在GridView的标记中设置EnableViewState=“true”,如下所示:

<asp:GridView ID="gridResults" runat="server" AllowPaging="True" AllowSorting="True"  PageSize="25"
                EnableViewState="true" CssClass="Grid" EmptyDataRowStyle-CssClass="GridEmpty"
                ShowHeaderWhenEmpty="false" EmptyDataRowStyle-BorderStyle="None" DataSourceID="objectDataSourceResults"
                AutoGenerateColumns="False" EmptyDataText="No records returned">

我必须在GridView的标记中设置EnableViewState=“true”,如下所示:

<asp:GridView ID="gridResults" runat="server" AllowPaging="True" AllowSorting="True"  PageSize="25"
                EnableViewState="true" CssClass="Grid" EmptyDataRowStyle-CssClass="GridEmpty"
                ShowHeaderWhenEmpty="false" EmptyDataRowStyle-BorderStyle="None" DataSourceID="objectDataSourceResults"
                AutoGenerateColumns="False" EmptyDataText="No records returned">


一些代码和标记可能会有所帮助!挑剔的;挑剔的请参阅编辑…一些代码和标记可能会有所帮助!挑剔的;挑剔的请参阅编辑。。。