Jump to content
999ANDRE999

Pesquisa em gridview com paginação

Recommended Posts

999ANDRE999

Vivam,

Tenho uma gridview com paginação (de momento tem 9paginas). quando aplico um filtro à grid, e o resultado aparece em mais que uma página, quando vou para mudar para a página 2, o filtro deixa de ser aplicado e aparecem todos os resultados (as 9 paginas).

O meu código está assim:

 protected void SearchButton_Click(object sender, EventArgs e)
    {
        string phone_search = TextBox_phone.Text;

        DataBase.Conecta();

        Npgsql.NpgsqlCommand comm = new Npgsql.NpgsqlCommand();
        comm.CommandText = " SELECT * FROM phone_book where LOWER(name_user) like '%" + phone_search + "%' OR UPPER(name_user) like '%" + phone_search + "%' OR name_user like '%" + phone_search + "%' OR phone_number like '%" + phone_search + "%'";
        comm.Connection = DataBase.Conn;

        Npgsql.NpgsqlDataAdapter myDataAdapter = new Npgsql.NpgsqlDataAdapter();
        myDataAdapter.SelectCommand = comm;
        DataSet myDataSet = new DataSet();
        int search_exist = myDataAdapter.Fill(myDataSet);

        GridView_phone.DataSource = myDataSet;
        GridView_phone.DataBind();

        DataBase.Desconecta();

    }

 protected void grdData_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView_phone.PageIndex = e.NewPageIndex;
        refresh_table();
    }
<asp:GridView ID="GridView_phone" runat="server" AutoGenerateColumns="False"  
                            HorizontalAlign="Center" AllowPaging="True" EmptyDataText="No data" 
                            ShowFooter="False" ShowHeaderWhenEmpty="True" 
                            OnPageIndexChanging="grdData_PageIndexChanging" Font-Size="Large">
                            <Columns>
                                <asp:TemplateField HeaderText="Name">
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("name_user") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Extension">
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("phone_number") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <FooterStyle BackColor="#565656" />
                            <HeaderStyle BackColor="#565656" ForeColor="#E4E4E4" />
                            <PagerStyle BackColor="#565656" ForeColor="#E4E4E4" HorizontalAlign="Center" 
                                VerticalAlign="Middle" />
                        </asp:GridView>

Alguem consegue ajudar? :thumbsup:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.