0

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

当我从页码中选择另一个页面时,搜索结果消失并显示列表,就像页面刷新一样。我该怎么办?我尝试了 OnSelectedIndexChanged 和 OnSelectedIndexChanging。并没有奏效。谢谢你。

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

2 回答 2

1

对于分页,您需要处理 PageIndexChanging。与 OnSelectedIndexChanged 无关。

例如:

方法

 protected void BindData()
        {
            string strConnection = "Data Source=.; uid=sa; pwd=wintellect;database=Rohatash;";
            SqlConnection con = new SqlConnection(strConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Userinfo", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            con.Close();
        }

页面索引更改

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }
于 2013-08-20T10:09:18.143 回答
0

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

于 2013-10-27T15:31:21.327 回答