private void Pesquisar(string valor) { DataTable tabela = new DataTable(); DataColumn coluna1 = new DataColumn("ID", Type.GetType("System.Int32")); DataColumn coluna2 = new DataColumn("CODIGO", Type.GetType("System.Int32")); DataColumn coluna3 = new DataColumn("DESCRICAO", Type.GetType("System.String")); DataColumn coluna4 = new DataColumn("CODAGENCIA", Type.GetType("System.String")); DataColumn coluna5 = new DataColumn("CODBANCO", Type.GetType("System.String")); DataColumn coluna6 = new DataColumn("DESBANCO", Type.GetType("System.String")); DataColumn coluna7 = new DataColumn("DESAGENCIA", Type.GetType("System.String")); tabela.Columns.Add(coluna1); tabela.Columns.Add(coluna2); tabela.Columns.Add(coluna3); tabela.Columns.Add(coluna4); tabela.Columns.Add(coluna5); tabela.Columns.Add(coluna6); tabela.Columns.Add(coluna7); PortadoresBL porBL = new PortadoresBL(); List<Portadores> portadores; portadores = porBL.PesquisarBuscaBL(valor); foreach (Portadores ltPor in portadores) { DataRow linha = tabela.NewRow(); linha["ID"] = ltPor.Id; linha["CODIGO"] = ltPor.Codigo; linha["DESCRICAO"] = ltPor.Descricao; if (ltPor.Banco != null) { linha["CODBANCO"] = ltPor.Banco.Codigo.ToString(); linha["DESBANCO"] = ltPor.Banco.Descricao; } else { linha["CODBANCO"] = ""; linha["DESBANCO"] = ""; } if (ltPor.Agencia != null) { linha["CODAGENCIA"] = ltPor.Agencia.Codigo.ToString(); linha["DESAGENCIA"] = ltPor.Agencia.Descricao; } else { linha["CODAGENCIA"] = ""; linha["DESAGENCIA"] = ""; } tabela.Rows.Add(linha); } dtbPesquisa = tabela; dtgPortadores.DataSource = tabela; dtgPortadores.DataBind(); }
public void pesquisaPortador(string lCampoPesquisa) { Session["tabelaPesquisa"] = null; DataTable dt = CriarTabelaPesquisa(); PortadoresBL porBL = new PortadoresBL(); Portadores po = new Portadores(); List<Portadores> portadores; if (this.txtPortador.Text != string.Empty && lCampoPesquisa != string.Empty) { portadores = porBL.PesquisarBuscaBL(this.txtPortador.Text); } else { portadores = porBL.PesquisarBL(); } foreach (Portadores pes in portadores) { DataRow linha = dt.NewRow(); linha["ID"] = pes.Id; linha["CODIGO"] = pes.Codigo; linha["DESCRICAO"] = pes.Descricao; dt.Rows.Add(linha); } if (dt.Rows.Count > 0) Session["tabelaPesquisa"] = dt; else { ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERTA", "alert('Portador não encontrado.');", true); } Session["objBLPesquisa"] = porBL; Session["objPesquisa"] = po; }