0
I have a project where I present a Gridview
in a Webforms project Asp.net C#.
I tried to apply the concept of 3 layer in this way, but the page only of the Reload and the grid does not appear in the page.
Follow the example of the code below:
public class bltboletoDAL
{
public DataTable GetDataGridView(DataTable Dt, int CodMorador)
{
MySqlDataReader Dr;
MySqlConnection Con = Conexao.GetConnection();
Conexao.AbrirConexao(Con);
MySqlCommand Cmd;
String Sql = "SELECT NumDocumento, Concat(Replace(Replace(Replace(Format(ValorBoleto, 2), '.', '|'), ',', '.'), '|', ',')) As ValorBoleto, DATE_FORMAT( VencimentoBoleto, '%d/%m/%y' ) AS 'VencimentoBoleto',DATE_FORMAT( DataPagamento, '%d/%m/%y' ) AS 'DataPagamento' From TbFatura where CodMorador=@v1 and Pago=1 ORDER BY VencimentoBoleto";
Cmd = new MySqlCommand(Sql, Con);
Cmd.Parameters.AddWithValue("@v1", CodMorador);
Dr = Cmd.ExecuteReader();
if (Dr.Read())
{
Dt.Load(Dr);
}
else
{
}
return Dt;
}
}
Business layer.
public class bltboletoBusiness
{
public void ViewGrid(GridView Grid)
{
Grid.Visible = true;
DataTable Dt = new DataTable();
var SetTable = new bltboletoDAL();
Dt = SetTable.GetDataGridView(Dt, ModuloGlobal.Global.CodMorador);
Grid.DataSource = Dt;
}
}
Viewing layer.
protected void btnUltimosPagamentos_Click(object sender, EventArgs e)
{
var blt = new bltboletoBusiness();
blt.ViewGrid(GridBltEmAberto);
GridBltEmAberto.Visible = true;
}
For those with the same or a difficulty close to this, was solved with . Databind() in the Business layer
– WesleyDSantos
where the Grid.Databind()?
– Marconi