我在更新面板中有一个网格视图。在网格视图的页脚中,我有一个下拉菜单,允许用户选择每页的记录数。用户第一次使用下拉菜单选择页面大小时,它可以工作。之后,下拉的选定索引更改事件仅每隔一次触发一次。因此,奇数的下拉选择,选择的索引更改触发,偶数次,选择的索引更改不会触发,并且下拉恢复到第一个选项,并且网格视图加载该数量的记录。
这是标记:
<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
并且选定的索引更改事件:
''' <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