Search code examples
c#asp.netajaxgridviewmodalpopupextender

Binding a gridview INSIDE ModalPopupExtender


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...

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.

Here is my HTML -

<cc1:ModalPopupExtender runat="server" ID="MPE_Issue" PopupControlID="pnlIssue" BackgroundCssClass="ModalPopupBG"
            TargetControlID="Hid_Sno" CancelControlID="btnIssueCancel">
        </cc1:ModalPopupExtender>
        <asp:Panel ID="pnlIssue" runat="server" Style="display: none" >
            <div class="HelloPopup">
                <div>
                    <br />
                    <h2>&nbsp;&nbsp;&nbsp;Issue Equipment</h2>
                    <br />
                    <asp:Panel runat="server" ID="pnlIssueSearch" DefaultButton="btnIssueSearch">
                        <div class="block" style="text-align: right; margin-left: 50px">
                            <asp:Label CssClass="lblBlock" runat="server" ID="lblIssueSearch" Text="Search:"></asp:Label>
                        </div>
                        <div class="block">
                            <asp:TextBox runat="server" ID="txtIssueSearch" Width="160px"></asp:TextBox>
                            <asp:ImageButton runat="server" ID="btnIssueSearch" ImageUrl="../Images/search.png" OnClick="btnIssueSearch_Click" />
                        </div>
                    </asp:Panel>
                    <asp:Panel runat="server" ID="pnlIssueSubmit" DefaultButton="btnIssueSubmit">
                        <div style="width: 275px; margin: auto; height: 295px; overflow: scroll;">
                            <asp:GridView runat="server" ID="gvIssue" AutoGenerateColumns="false" CssClass="mGrid" OnRowCommand="gvIssue_RowCommand">
                                <Columns>
                                    <asp:TemplateField HeaderText="Qty">
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtIssueQty" runat="server" Text='<%# Bind("QTY") %>'></asp:TextBox>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField HeaderText="Assignment" DataField="FIRST_NAME" />
                                </Columns>
                            </asp:GridView>
                        </div>
                        <div class="center">
                            <asp:Button runat="server" ID="btnIssueSubmit" Text="Issue" OnClick="btnIssueSubmit_Click" />
                            <input type="button" id="btnIssueCancel" value="Cancel" />
                        </div>
                    </asp:Panel>

And the codebehind -

    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();

    }

EDIT/SOLUTION 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).

Thanks all for the suggestions and help.


Solution

  • 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).