So I have a new requirement that is tricky to me and I'm unable to figure out so far. I am using a gridview to insert, and update data. One of the requirements that I have is when a user manually adds a new record, if the same "deal number" exists then display a pop up. This pop up should show the record that already exists. They should be able to click 1 of 3 buttons which are "use", "discard", or "Ok". The "use" button will basically close the pop up and clear the textboxes the user was entering in. The "discard" button must delete the record that exists so the user can insert the new record using that same deal number. The reason for this is because the deal number is the most unique number for the "deals" that occur. With the way we are exporting from an old application to a new one, duplicates are downloaded, sometimes some with more information than the first time it was exported. This is why I must add a requirement for the user to choose which record for them to keep. I hope this makes sense to you all. I have dried a few things, but this is what I currently have and I'm stuck on. 

The Jquery Script:

```
<script type="text/javascript">
    $(document).ready(function () {
        function showpopup() {
            $("#popup").dialog("open");
        }

        $("#popup").dialog({
            modal: true,
            width: 450,
            autoOpen: false,
            open: function (type, data) {
                $(this).parent().appendTo("form");
            }
        });

        $("#popup").each(function () {
            var popup = $(this);
            popup.parent().appendTo($("form:first"));
        });
    });
</script>

```

And now the division the script calls which has another gridview to display the existing record..

```
<div class="popUpStyle" title="Duplicate Deal Found!" id="popup" style="display:none">
            <asp:GridView ID="gvDealTracking" runat="server" Width="200px" AutoGenerateColumns="False">
                <Columns>
                    <asp:TemplateField HeaderText="Stock #">
                        <ItemTemplate>
                            <asp:Label ID="lblDupStockNumber" runat="server" Text='<%# Bind("StockNumber") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Deal #">
                        <ItemTemplate>
                            <asp:Label ID="lblDupDealNumber" runat="server" Text='<%# Bind("FIMAST") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="DealDate">
                        <ItemTemplate>
                            <asp:Label ID="lblDupDealDate" runat="server" Text='<%# Bind("DealDate") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Buyer">
                        <ItemTemplate>
                            <asp:Label ID="lblDupBuyer" runat="server" Text='<%# Bind("Buyer") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="GrossProfit">
                        <ItemTemplate>
                            <asp:Label ID="lblDupGrossProfit" runat="server" Text='<%# Bind("GrossProfit") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="AmtFinanced">
                        <ItemTemplate>
                            <asp:Label ID="lblDupAmtFinanced" runat="server" Text='<%# Bind("AmtFinanced") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="BankName">
                        <ItemTemplate>
                            <asp:Label ID="lblDupBankName" runat="server" Text='<%# Bind("BankName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <br />
            <asp:Button ID="btnUse" Text="Use" runat="server"></asp:Button>
            <asp:Button ID="btnDiscard" Text="Discard" runat="server" OnClick="btnDiscard_Click" style="display:none"></asp:Button>
            <asp:Label ID="lblMessagePop" runat="server"></asp:Label>
            <br />
        </div>

```

And now the code behind that I use to try to delete the existing record..

```
 protected void btnDiscard_Click(object sender, EventArgs e)
        {
            try
            {
                GridViewRow gvr = (GridViewRow)(sender as Control).Parent.Parent;
                string dealnumber = ((Label)gvr.FindControl("lblDupDealNumber")).Text.Trim();

                conn.Open();
                SqlCommand cmdDeleteDup = new SqlCommand("DELETE * FROM Vehicle WHERE FIMAST = @FIMAST", conn);
                cmdDeleteDup.Parameters.AddWithValue("@FIMAST", dealnumber);
                cmdDeleteDup.ExecuteNonQuery();
                conn.Close();

            }
            catch (Exception ex)
            {
                lblMessagePop.Text = ex.ToString();
            }
        }

```

The button click isn't not firing and I do now know how to make it work. I tried a few different things but same results. I'm using a reader that checks to see if the record does exists and I show this pop up if it does have rows. It displays perfectly, just my buttons don't do anything. If this isn't the proper way to go about this, please let me know. Any guidance is greatly appreciated!

This is how I'm calling the popup in c#. This has reader that checks to see if the rows exist, and if so, it displays the existing record in the popup. I use a data adapter to do this. Then I use Page.ClientScript... to open the popup and display the results.

```
SqlDataReader rdr = null;
                SqlCommand cmdCheckExisting = new SqlCommand("SELECT StockNumber, DealDate, Buyer FROM Vehicle WHERE FIMAST = '" + DealNumber + "';", conn);
                rdr = cmdCheckExisting.ExecuteReader();
                if (rdr.HasRows)
                {
                    rdr.Close();
                    DataTable dt = new DataTable();
                    SqlDataAdapter cmdReturnExisting = new SqlDataAdapter("SELECT StockNumber, FIMAST, DealDate, Buyer, GrossProfit, AmtFinanced, BankName FROM Vehicle WHERE FIMAST = '" + DealNumber + "';", conn);
                    cmdReturnExisting.Fill(dt);
                    gvDealTracking.DataSource = dt;
                    gvDealTracking.DataBind();

                    conn.Close();

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "showpopup();", true);
                }

```