为Gridview分页不正确

为Gridview分页不正确

本文介绍了为Gridview分页不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索页面。在列表中显示搜索结果。

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

当我从页码中选择另一页时,搜索结果消失并显示列表,如刷新页面。我该怎么办?我尝试了OnSelectedIndexChanged和OnSelectedIndexChanging。并没有工作。

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>


推荐答案

尝试在aspx页面的数据源中启用ViewState添加EnableViewState =true和ViewStateMode =Enabled

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

这篇关于为Gridview分页不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:35