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.
– markim
table
is void.– Jéf Bueno
How do I stop my table from being null.
– markim
Check the conversion.
grvListaFuncionarios.DataSource as DataTable
will returnnull
ifgrvListaFuncionarios.DataSource
cannot be converted toDataTable
.– Jéf Bueno
Datatable table = ((Datatable)grvListaFunctions.Datasource); So it gives an error saying that I cannot perform this conversion.
– markim
<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
– markim