How to apply the 3-tier concept with GridView C #?

0

I have a project where I present a Gridview in an ASP.NET C # Webforms project. I tried to apply the 3 layer concept in this way, but the page only reload and the grid does not appear on the page.

Follow the code example 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;
    }
}

Display layer.

protected void btnUltimosPagamentos_Click(object sender, EventArgs e)
    {
        var blt = new bltboletoBusiness();
        blt.ViewGrid(GridBltEmAberto);

        GridBltEmAberto.Visible = true;
    }
    
asked by anonymous 05.08.2015 / 19:25

1 answer

1

You have to call the DataBind method of the grid:

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;
    Grid.DataBind();
}
    
15.09.2015 / 18:47