Forum guidelines
AuthorQuestion
Problem with Events of Dynamic Created GridView
Posted on: 03 May 2010
Hi,

    In my Application, I have created on GridView At Design Time. On RowDataBound Event I add One more Row to the grid. In that Row I added on Div and Inside that div I have created a Gridview dynamically. On Click of one of the Cell of Static grid I set Display Property Of Div to None or Blank to make Dynamic created grid InVisible/Visible respectively. 
      This functionality working fine with me. Now when I want to go to another Page on the click of one of cell of Dynamically created Grid with the all data contain in that clicked Cells Row. For Dynamic Grid I have Added few events such as "RowDataBound", "SelectedIndexChanging" etc. Out of All written Events only RowDataBound event is firing other events not firing in my case.
        Again to check further, I add LinkButton to one cell and add click event to that button in RowDataBound Event of Dynamic Grid. Still Link Button Click event not firing. 
So I wonder why this is happening.  Any Clue regarding This issue. 

      Is there any Link with Event Firing and Page's Postback or DataBind

Thanks,

   VIkram

AuthorReply
Re: Problem with Events of Dynamic Created GridView
Posted on: 03 May 2010  
hi friend,

 i have gave you solution for this problem in your previous thread... check there...

=====================================
Amit Choudhary
MicrosoftMVP MindcrackerMVP Blog: www.cshandler.com
Follow @vendettamit

Re: Problem with Events of Dynamic Created GridView
Posted on: 03 May 2010  

Hi Amit,
    Thanks for reply. Actually I have added same code which you mentioned in previous code. But that event not firing.
   I have added following Code in my RowDataBound Event of Dynamic GridView.   
 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
    }

Still The Click Event not Firing.
Thanks,
  VIkram
 
 

Re: Problem with Events of Dynamic Created GridView
Posted on: 03 May 2010  
hi friend,

i have tried this code by creating a dummy page... its working great..

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

... check for if you have some validations control added on your page because some times it prevent the controls from firing the events.

Let me know if it helps you.

=====================================
Amit Choudhary
MicrosoftMVP MindcrackerMVP Blog: www.cshandler.com
Follow @vendettamit

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.