Vikram

Vikram

  • 1.5k
  • 276
  • 308.8k

Click Event for Link Button not Firing In Dynamic Grid View

Apr 30 2010 6:52 AM
Hi,

    I have one Dynamically created Grid View. I have attached RowDataBound event for created GridView which is firing properly. When I add Other Events to the same GridView those are not firing.

Here is my code snippet :

gv.RowDataBound += new GridViewRowEventHandler(gv_RowDataBound);            

gv.SelectedIndexChanging += new GridViewSelectEventHandler(gv_SelectedIndexChanging);
           
gv.RowCommand += new GridViewCommandEventHandler(gv_RowCommand); 

And Respective Definitions:

 protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
LinkButton lbtn = new LinkButton();
         lbtn.Text = e.Row.Cells[1].Text;
                lbtn.Click += new EventHandler(lbtn_Click);
                e.Row.Cells[1].Controls.Add(lbtn);
}
   }

void lbtn_Click(object sender, EventArgs e)
    {
       //My Code
    }

protected void gv_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        // My Code
    }

protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //My Code
    }

Is there any specific property require to set for this.
Any Help Appreciated .............

The Code in Red is my code for LinkButton. Given Link Button Click event not firing.

Is there any link of Postback and Event Firing?







Answers (10)