Button click event, added dynamically, does not work

1

I'm working on a page that loads a list of items into a GridView . Content is loading normally, but there was a need to add a cell with text and two buttons. With the code below you are adding the elements, however the click of the button is not working.

    protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
    {

            if (e.Row.RowType != DataControlRowType.DataRow) return;

                e.Row.BackColor = System.Drawing.Color.Red;

                var btnEdit = new LinkButton
                {
                    Text = "Edit",
                };

                btnEdit.Click += btnEdit_Click;

                var btnRemove = new Button
                {
                    Text = "Remove",
                    ID = e.Row.Cells[1].Text

                };


                btnRemove.Click += btnRemove_Click;

                var chave = new Label
                {
                    Text = e.Row.Cells[1].Text
                };

                e.Row.Cells[1].Controls.Add(chave);
                e.Row.Cells[1].Controls.Add(btnRemove);
                e.Row.Cells[1].Controls.Add(btnXml);

            }

    private void btnEdit_Click(object sender, EventArgs e)
    {

    }

    private void btnRemove_Click(object sender, EventArgs e)
    {

    }
    
asked by anonymous 14.09.2016 / 21:08

0 answers