Search Gridview Asp.net data

Asked

Viewed 184 times

2

I have a GridView called grvListaFuncionario which is populated by data from my database. I am facing a problem when searching the data on it.

private void Pesquisar()
{

    DataTable table = new DataTable();
    table = grvListaFuncionarios.DataSource as DataTable;

    table.DefaultView.RowFilter = " nome like '%" + txtPesquisar.Text + "%'" +
                                       "or cargo like '%" + txtPesquisar.Text + "%'" +
                                       "or salário like '%" + txtPesquisar.Text + "%'";

    grvListaFuncionarios.DataSource = table;
    grvListaFuncionarios.DataBind();
}

The following error is returned:

Additional information: Undefined object reference for an object instance.

  • Now that I’ve seen the mistakes of Portuguese, I’m sorry.

  • table is void.

  • How do I stop my table from being null.

  • Check the conversion. grvListaFuncionarios.DataSource as DataTable will return null if grvListaFuncionarios.DataSource cannot be converted to DataTable.

  • Datatable table = ((Datatable)grvListaFunctions.Datasource); So it gives an error saying that I cannot perform this conversion.

  • <Asp:Templatefield Headertext="Name"> <Edititemtemplate> <Asp:Textbox ID="txtNome" runat="server" Text='<%# Bind("Name") %>'></Asp:Textbox> </Edititemtemplate> <Itemtemplate> <Asp:Label ID="lblNome" runat="server" Text='<%# Bind("Name") %>'></Asp:Label> </Itemtemplate> </Asp:Templatefield> I fill my gridView this way. The mistake may be because of this

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.