1

I have a grid view in an update panel. In the footer of the grid view, I have a drop down allowing the user to select the number of records per page. The first time the user selects a page size using the drop down, it works. After the that, the selected index changed event of the drop down only fires every other time. So, odd numbered selections of drop down, selected index changed fires, even numbered times, selected index changed does not fire, and drop down reverts to first option, and grid view loads with that number of records.

Here is the markup:

<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> 

Not sure what code to include. I set the drop down item:

''' <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 

And the selected index changed event:

 ''' <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 
2
  • 1
    Some code and markup may help! Commented Aug 6, 2013 at 17:31
  • Picky picky ;) See edits... Commented Aug 6, 2013 at 18:58

1 Answer 1

1

I had to set EnableViewState="true" in the markup for GridView like this:

<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"> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.