How do I not lose the rows of my GridView that were created dynamically in RowDataBound?

2

Thegridisalreadybeingmountedcorrectly.ButwhenIgiveaPostBackbyclickingonabuttononthepage,thegridstaysandonlytheheaders(purplelines)disappear.IknowifIcallthemethodtoreloadthegridagain,itworks,butitdoesnotseemtometobeagoodthingtodo.

Codeforcreatingdynamicheaders.

protectedvoidgrvAvaliacao_RowDataBound(objectsender,GridViewRowEventArgse){if(e.Row.RowType==DataControlRowType.DataRow){//SemudaroHeadif(!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;
                }
            }
        }
    
asked by anonymous 13.11.2014 / 18:05

1 answer

-1

Leave the headers for 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
}
    
13.11.2014 / 22:48