0

I programmatically created ImageButton on RowDataBound Event. I want to make ModalPopup appear when the ImageButton is clicked. How can i create an ImageButton_Click Event for the ImageButton?

 protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[index].Controls.Add
                (new ImageButton { ImageUrl = "Images/img.png", ID = "imgbtn" });
         } 
     }
Seehyung Lee
  • 590
  • 1
  • 15
  • 32
  • 1
    Don't create dynamic controls in `RowDataBound` but in `RowCreated`. The former is only executed on databinding whereas the latter is executed on every postback. – Tim Schmelter May 07 '13 at 14:43
  • Thank you for the suggestion. I'll try to put it in RowCreated. – Seehyung Lee May 07 '13 at 14:47
  • Here's you can learn how to subscibe to events programmatically (`+=` syntax): http://msdn.microsoft.com/en-us/library/ms366768.aspx – Tim Schmelter May 07 '13 at 14:50

0 Answers0