1

I have a GridView .In this GridView we are dynamically generating columns . We have also set Autogenerate columns to true in the GridView. Now the issue I am dynamically adding linkbutton to that columns .

ISSUE : Link button click is not working .It is doing a postback and all the links are disappeared.I have tried adding commands and click event but none of them are working. Any help would be appreciated.

Code Behind :

     protected void GridViewTest_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null && e.Row.RowType == DataControlRowType.DataRow)
            {



                      for (int i = 0; i < e.Row.Cells.Count; i++)
                    {

                         LinkButton link = new LinkButton();


                         link.Text = e.Row.Cells[i].Text;

                         link.EnableViewState = true;
                          link.Click += new EventHandler(onLinkClick);

                         e.Row.Cells[i].Controls.Add(link);                  

                     }
                 }
            }



  protected void onLinkClick(object sender, EventArgs e)
        {
            this.ModalPopupExtender1.Show();
        } 

ASPX :

 <asp:GridView
                            ID="GridViewTest"
                            runat="server"
                            AutoGenerateColumns="true"
                            CssClass="resultsTable"
                            Width="100%"
                            CellPadding="2"
                            CellSpacing="0"
                            GridLines="None"
                            autogenerateeditbutton="true"                                
                            OnRowDataBound="GridViewPullHistory_RowDataBound"
                            OnRowCreated="GridViewPullHistory_RowCreated">
                            <AlternatingRowStyle CssClass="gridRow1" HorizontalAlign="Center" />
                            <RowStyle CssClass="gridAltRow1" HorizontalAlign="Center" />
                            <HeaderStyle CssClass="gridHeader" Font-Bold="true"  HorizontalAlign="Right" />
                        </asp:GridView>
Sabilv
  • 602
  • 1
  • 15
  • 44
user2465036
  • 351
  • 2
  • 11
  • 24
  • so what' s the problem? Any errors? – DAG Jun 07 '13 at 22:38
  • Link button click event is not working – user2465036 Jun 09 '13 at 17:12
  • "not working" is not an error-report. Be specific! – DAG Jun 09 '13 at 19:18
  • When i am clicking the links in the Gridview . I am not able to get the handle link button click event . Link Button Click is not excecuted in the postback .As a result all the links are gone and i also i am not able to get the value of the clicked link button . – user2465036 Jun 09 '13 at 22:31
  • AnyOne there? Sorry Christian Gartner for not so being specific – user2465036 Jun 09 '13 at 23:43
  • are you trying assign the link button to display? you have to set select link button to true –  Jun 10 '13 at 02:23
  • I believe in your page load you already code like this : 'if (!IsPostBack) { filldata() }' but i still curious, you want to show modal popup extender by click the link, right ? why not to assign button in your pop up modal extender code? – Sabilv Jun 10 '13 at 05:33
  • Can you create the controls on Init? Please check this answer: http://stackoverflow.com/a/4218690/1193236 – Jan Sommer Jun 16 '13 at 16:42

1 Answers1

0

Just register a PostBack trigger (since you are using an UpldatePanel):

ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(link);