How do I not lose my Gridview lines that were dynamically created in Rowdatabound?

Asked

Viewed 221 times

2

Aqui esta a Grid montada corretamente

The grid is already being mounted correctly. However when I give a Postback by clicking on some button on the page, the grid is maintained and only the headers (lines in purple) disappear. I know if I call the method to reload the grid again, it works, but it doesn’t seem like a good thing to do.

Code for creating dynamic headers.

  protected void grvAvaliacao_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Se mudar o Head
                if (!DataBinder.Eval(e.Row.DataItem, "NAT_Nome").Equals(Session["Competencia"]))
                {
                    Session["Competencia"] = DataBinder.Eval(e.Row.DataItem, "NAT_Nome");
                    this.head = true;
                }

                if (this.head)
                {
                    GridViewRow linha = CriarCabecalho(e);

                    //linha -> tabela
                    var tabela = e.Row.Parent as Table;
                    tabela.Rows.AddAt(tabela.Rows.Count - 1, linha);

                    this.head = false;
                }
            }
        }
  • Add the Page_load code. There you have to check if ! Ispostback. [This graphical interface/ table is beautiful]

  • Hello Tony! Yes there I already do this check, but the loading of my grid is in the event of a button.

1 answer

-1

Let headers be created at other events, such as RowCreated and the RowCommand:

protected void grvAvaliacao_RowCommand(object sender, GridViewRowEventArgs e) {
    // Coloque aqui a criação dos cabeçalhos
}

protected void grvAvaliacao_RowCreated(object sender, GridViewRowEventArgs e) {
    // Coloque aqui a criação dos cabeçalhos
}
  • Hello Gypsy! I tried to implement their 2 suggestions and got the following problems: In Rowcommand, if I create the headers there, they are appeared when I click something. In Rowcreate, I miss the Gridviewroweventargs that I use to popular a header column (Gridviewrow row = Piggyback(and);).

  • @alexanderPataki You tried to leave in the three events at the same time?

Browser other questions tagged

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