0
Answer

Bad DropDownList - DataGrid interaction

kiki

kiki

16y
3.2k
1

Hello,

theres a part of code in my webpage:


.aspx code
<body>
<form id="form3" runat="server">
<asp:DataGrid
            runat="server"
            ID="ResGrid"
            AllowPaging="True"
            onPageIndexChanged="setPage"
            PageSize="15" >
</asp:DataGrid>

<asp:Panel
            runat="server"
            ID="Panel1"
            GroupingText="Preferences" >       
           
                Number of results per page:
                <asp:DropDownList ID="selectNumResPerPage" runat="server" AutoPostBack="true">
                    <asp:ListItem Value=10> 10 </asp:ListItem>
                    <asp:ListItem Value=15> 15 </asp:ListItem>
                    <asp:ListItem Value=20> 20 </asp:ListItem>
                    <asp:ListItem Value=25> 25 </asp:ListItem>
                    <asp:ListItem Value=30> 30 </asp:ListItem>
                </asp:DropDownList>
            <br />
            <asp:Button ID="submitPre" runat="server"  Text="save changes" UseSubmitBehavior="true" OnClick="submitPre_Click"/>
</asp:Panel>
        </form></body>


.aspx.cs code

protected void submitPre_Click(object sender, EventArgs e)
    {
        ResGrid.PageSize = Convert.ToInt32(selectNumResPerPage.SelectedValue);
    }

The problem with this program is that I have to click the
submitPre button twice in order to change the PageSize value. While I run my program, I change the selected value of the dropdownlist, I click on the "save changes" button, the page reloads, but there's no change. When I click on the button again and the page reloads for second time, then theres a the change I want to do. Why is that happening;

Can anyone help me please?