asp.netgridviewpagination

Paging for Gridview doesn't work correct


I have a search page. In list the search results are displayed.

When I select another page from page numbers, the search result is disappeared and show the list like the page is refreshed. What should I do? I tried OnSelectedIndexChanged and OnSelectedIndexChanging. And didn't work. Thank you.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" 
                    CellPadding="4" DataSourceID="ahsun" ForeColor="#333333" GridLines="None" Width="100%"
                    DataKeyNames="SICIL_NO" OnSelectedIndexChanged="LinkButton1_Click" CssClass="icerik" o >
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"  />
                    <Columns>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"
                                    CssClass="hover" Text="Seç"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
<asp:TemplateField HeaderText="Adı" SortExpression="ADI">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton3" runat="server" Text='<%# Bind("ADI") %>' CausesValidation="False"
                                    CommandName="Select" CssClass="hover"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Soyadı" SortExpression="SOYADI">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton4" runat="server" Text='<%# Bind("SOYADI") %>' CausesValidation="False"
                                    CommandName="Select" CssClass="hover"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Birimi" SortExpression="BIRIMI">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton5" runat="server" Text='<%# Bind("BIRIMI") %>' CausesValidation="False"
                                    CommandName="Select" CssClass="hover"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Görevi" SortExpression="GOREVI">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton6" runat="server" Text='<%# Bind("GOREVI") %>' CausesValidation="False"
                                    CommandName="Select" CssClass="hover"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>

                    </Columns>
                    <RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" />
                    <EditRowStyle BackColor="#2461BF" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <asp:SqlDataSource ID="ahsun" runat="server" ConnectionString="<%$ ConnectionStrings:oraLiveConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:oraLiveConnectionString.ProviderName %>"
                    SelectCommand="select  SICIL_NO, ADI, SOYADI, BIRIMI ,GOREVI,PERSON_ID from xxah_hr_calisanlar WHERE SICIL_NO <> '01470' "></asp:SqlDataSource>
                <br />
                <asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4" DataKeyNames="SICIL_NO"
                    DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="50px"
                    Width="100%" CaptionAlign="Left" AutoGenerateRows="False" CssClass="icerik">
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
                    <EditRowStyle BackColor="#2461BF" />
                    <RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" Width="75%" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" Width="25%" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"
                        Width="25%" />
                    <AlternatingRowStyle BackColor="White" />
                    <Fields>
<asp:BoundField DataField="ADI" HeaderText="Adı" SortExpression="ADI" />
                        <asp:BoundField DataField="SOYADI" HeaderText="Soyadı" SortExpression="SOYADI" />
<asp:BoundField DataField="BIRIMI" HeaderText="Birimi" SortExpression="BIRIMI" />
                        <asp:BoundField DataField="GOREVI" HeaderText="G&#246;revi" SortExpression="GOREVI" />
</Fields>
                </asp:DetailsView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:oraLiveConnectionString %>" EnableCaching="True"
                    ProviderName="<%$ ConnectionStrings:oraLiveConnectionString.ProviderName %>"
                    SelectCommand="select c.* from TABLE c where c.SICIL_NO=:sicil" >
                    <SelectParameters>
                        <asp:ControlParameter ControlID="GridView1" Name="sicil" PropertyName="SelectedValue" />
                    </SelectParameters>
                </asp:SqlDataSource>

Solution

  • Try enabling ViewState on the datasource in your aspx page by adding EnableViewState="true" and ViewStateMode="Enabled"