title: Binding a gridview INSIDE ModalPopupExtender
body: <p>I have searched about this topic all over the internet and have come up with nothing.  Either I am having a hardtime wording my problem or I am do something so wrong that no one else has ever even tried it...</p>
  
  <p>I have a gridview.  I am using a button in the gridview to execute a command to open a ModalPopupExtender.  That part works great.  Once I have the popup open, I want to be able to press a button to execute a function which will perform a Sql query and bind a gridview that is INSIDE the popup panel.  After that the user can perform an action with the gridview which would close the modal popup.</p>
  
  <p>Here is my HTML - </p>
  
  <pre><code>&lt;cc1:ModalPopupExtender runat="server" ID="MPE_Issue" PopupControlID="pnlIssue" BackgroundCssClass="ModalPopupBG"
              TargetControlID="Hid_Sno" CancelControlID="btnIssueCancel"&gt;
          &lt;/cc1:ModalPopupExtender&gt;
          &lt;asp:Panel ID="pnlIssue" runat="server" Style="display: none" &gt;
              &lt;div class="HelloPopup"&gt;
                  &lt;div&gt;
                      &lt;br /&gt;
                      &lt;h2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Issue Equipment&lt;/h2&gt;
                      &lt;br /&gt;
                      &lt;asp:Panel runat="server" ID="pnlIssueSearch" DefaultButton="btnIssueSearch"&gt;
                          &lt;div class="block" style="text-align: right; margin-left: 50px"&gt;
                              &lt;asp:Label CssClass="lblBlock" runat="server" ID="lblIssueSearch" Text="Search:"&gt;&lt;/asp:Label&gt;
                          &lt;/div&gt;
                          &lt;div class="block"&gt;
                              &lt;asp:TextBox runat="server" ID="txtIssueSearch" Width="160px"&gt;&lt;/asp:TextBox&gt;
                              &lt;asp:ImageButton runat="server" ID="btnIssueSearch" ImageUrl="../Images/search.png" OnClick="btnIssueSearch_Click" /&gt;
                          &lt;/div&gt;
                      &lt;/asp:Panel&gt;
                      &lt;asp:Panel runat="server" ID="pnlIssueSubmit" DefaultButton="btnIssueSubmit"&gt;
                          &lt;div style="width: 275px; margin: auto; height: 295px; overflow: scroll;"&gt;
                              &lt;asp:GridView runat="server" ID="gvIssue" AutoGenerateColumns="false" CssClass="mGrid" OnRowCommand="gvIssue_RowCommand"&gt;
                                  &lt;Columns&gt;
                                      &lt;asp:TemplateField HeaderText="Qty"&gt;
                                          &lt;ItemTemplate&gt;
                                              &lt;asp:TextBox ID="txtIssueQty" runat="server" Text='&lt;%# Bind("QTY") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                          &lt;/ItemTemplate&gt;
                                      &lt;/asp:TemplateField&gt;
                                      &lt;asp:BoundField HeaderText="Assignment" DataField="FIRST_NAME" /&gt;
                                  &lt;/Columns&gt;
                              &lt;/asp:GridView&gt;
                          &lt;/div&gt;
                          &lt;div class="center"&gt;
                              &lt;asp:Button runat="server" ID="btnIssueSubmit" Text="Issue" OnClick="btnIssueSubmit_Click" /&gt;
                              &lt;input type="button" id="btnIssueCancel" value="Cancel" /&gt;
                          &lt;/div&gt;
                      &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>And the codebehind - </p>
  
  <pre><code>    protected void gv1_RowCommand(object sender, GridViewCommandEventArgs e)
          {
              if (e.CommandName == "issue")
              {
                  GridViewRow gvr3 = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
                  string itemNo = ((Label)gvr3.Cells[0].FindControl("lblItemNo")).Text;
                  btnIssueSubmit.Visible = false;
                  txtIssueSearch.Text = "";
  
                  MPE_Issue.Show();
  
              }        
      protected void btnIssueSearch_Click(object sender, ImageClickEventArgs e)
      {
          string query = "SELECT QTY, NEW_EMP_ID as NAME FROM TRANSACTION_TRACKING WHERE NEW_EMP_ID = @inputINT";
          string inputString = "%" + txtIssueSearch.Text + "%";
          int inputINT = Convert.ToInt32(txtIssueSearch.Text);
  
          SqlConnection con = new SqlConnection(CS);
          SqlDataAdapter da = new SqlDataAdapter(query, con);
          SqlParameter parameter = new SqlParameter("inputString", inputString);
          SqlParameter parameter2 = new SqlParameter("inputINT", inputINT);
          da.SelectCommand.Parameters.Add(parameter);
          da.SelectCommand.Parameters.Add(parameter2);
  
          DataSet ds = new DataSet();
          da.Fill(ds);
          gvIssue.DataSource = ds;
          gvIssue.DataBind();
  
          btnIssueSubmit.Visible = true;
  
          MPE_Issue.Show();
  
      }
  </code></pre>
  
  <p><strong>EDIT/SOLUTION</strong>
  I was going about solving this problem wrong.  I wanted to override the nature of asp.net instead of going with the flow and solving the problem systematically.  To overcome this issue I changed my data bind into its own method and had the button within the panel activate the that method, set the popup control to Open(), and also set a boolean from false to true.  Then on the page_load I have an event that checks the boolean and automatically does the data Method if it is true (and therefore a search parameter is in the textbox).</p>
  
  <p>Thanks all for the suggestions and help.</p>