how to populate modalpopupextender when gridview button is clicked in asp.net

Laziale picture Laziale · Dec 15, 2011 · Viewed 15.6k times · Source

I have one problem, someone maybe can help me. I have a gridview and a button to edit the fields in the gridview from within a modalpopupextender. What I want to achieve is when someone will click the edit button, the popup to have the data from the row which needs to be edited. As it is now, when someone clicks the edit button, the popup comes up but with blank textboxes/dropdowns there. Here is what I have at this moment:

<ItemTemplate>
   <asp:Button ID="btnEdit" CausesValidation="false" 
       runat="server" Text="Edit" OnClick="Activatee" />
  <ajaxToolkit:ConfirmButtonExtender ID="btnDeactivatePopup" runat="server" 
       TargetControlID="btnEdit" DisplayModalPopupID="ModalPopupDeactivate" />
  <ajaxToolkit:ModalPopupExtender 
       ID="ModalPopupDeactivate" runat="server" TargetControlID="btnEdit" 
       PopupControlID="pnlActivate" OkControlID="btnDeactivateOK" 
       CancelControlID="btnDeactivateCancel" BackgroundCssClass="modalBackground" 
       DynamicServicePath="" Enabled="true" />
</ItemTemplate>

I tried with another method when the button is clicked, but when I am clicking the edit button, the popup doesn't come out at the page:

  <ItemTemplate>
    <asp:Button ID="btnEdit" CausesValidation="false" 
          runat="server" Text="Edit" OnClick="getData" />
    <!-- 
    <ajaxToolkit:ConfirmButtonExtender ID="btnDeactivatePopup" 
          runat="server" TargetControlID="btnEdit" 
          DisplayModalPopupID="ModalPopupDeactivate" /> 
    -->
    <ajaxToolkit:ModalPopupExtender ID="ModalPopupDeactivate" 
          runat="server" TargetControlID="btnEdit" PopupControlID="pnlActivate"
          OkControlID="btnDeactivateOK" CancelControlID="btnDeactivateCancel" 
          BackgroundCssClass="modalBackground" DynamicServicePath="" Enabled="true" />
 </ItemTemplate>

And here is the backend code too for the version above but it doesn't show the popup at the end:

 protected void getData(object sender, EventArgs e)
 {
      string coef = "";
      Button btn = (Button)sender;
      GridViewRow gvr = (GridViewRow)btn.NamingContainer;
      int rowindex = gvr.RowIndex;
      GridViewRow roww = gvGDG.Rows[rowindex];
      coef = Convert.ToString(roww.Cells[7].Text);
      txtCoefficient.Text = coef;
      ModalPopupExtender modalPopupExtender1 = 
         (ModalPopupExtender)gvGDG.Rows[rowindex].FindControl("ModalPopupDeactivate");
      modalPopupExtender1.Show();
 }

I hope someone can help me with this. Thanks a lot, Laziale

Answer

Jon P picture Jon P · Dec 15, 2011

As Pauls link is no longer working, here is an answer to a similar question on SO

PopUpExtender on ImageButton inside GridView problem

The links in the answer are to the same source as Pauls answer and when I checked they are dead too. But there is a summary of the code in that answer. That should help you.