You should add dynamic controls in
RowCreated[
^] event of the GridView. This will create controls at DataBinding and as well as when rebuilding a page on PostBack.
Try this:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var firstCell = e.Row.Cells[1];
firstCell.Controls.Clear();
Button btn_Check = new Button();
btn_Check.ID = "btn_Check";
btn_Check.Text = firstCell.Text;
btn_Check.Click += new EventHandler(btn_Check_Click);
firstCell.Controls.Add(btn_Check);
}
}
protected void btn_Check_Click(object sender, EventArgs e)
{
Response.Write("btn_Check_Click event called");
}
--Amit