Event Button click, added dynamically, does not work

Asked

Viewed 339 times

1

I’m working on a page that loads a list of items into a GridView. The content is being loaded normally, but the need to add a cell with a text and two buttons. With the code below is adding the elements, however the event click 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)
    {

    }
No answers

Browser other questions tagged

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