0

我想使用 jQuery Dialog WIDGET 在我的 SQL Server 数据库中插入数据。在 jQuery 小部件中,我有多个字段和一个提交按钮,如果用户按下提交,记录将被输入数据库并自动关闭对话框。参考链接上的代码很有帮助,但我想将它插入我的数据库。请帮我解决这个问题,我真的坚持了好几天了。我什至没有示例代码可以在这里发布,但我所做的是:

function linkbtnTest(abc) {
    $(abc).dialog({

        modal: true,
        buttons: { "OK": function () { $(this).dialog("Close") } },
        open: function (type, data) { $(this).parent().appendTo("form") },

        height: 600,
        width: 800
    });
}


<div id='<%# Eval("LCID") %>' style="display: none;">
                            <table>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblInvoiceNumber" runat="server" Text="Invoice Number">
                                        </asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblInvoiceDate" runat="server" Text="Invoice Date">
                                        </asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblBLNumber" runat="server" Text="B/L Number">
                                        </asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblBLDate" runat="server" Text="B/L Date">
                                        </asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="txtInvoiceNumber" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtInvoiceDate" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtBLNumber" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtBLDate" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblVesselName" runat="server" Text="Invoice Number">
                                        </asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblVoyageNumber" runat="server" Text="Invoice Date">
                                        </asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblDueDate" runat="server" Text="B/L Number">
                                        </asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblShipmntSchedule" runat="server" Text="B/L Date">
                                        </asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="txtVesselName" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtVoyageNumber" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtDueDate" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtShipmntSchedule" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                            </table>
                        </div>
4

1 回答 1

2

看看我如何使用 Jquerymodel 弹出窗口插入简单的组名及其父 ID。

$("#create-group")
        .button()
        .click(function () {
            $("#dialog-form").dialog("open");
        });

        $("#dialog-form").dialog({
            autoOpen: false,
            height: 150,
            width: 260,
            modal: true,
            buttons: {
                "Add": function () {

                //start validation
                    var bValid = true;
                    allFields.removeClass("ui-state-error");
                   //add all ur validation here                 
                //end validation
                    if (bValid) {

                        //var pid = $('#<%=hfInstrumentid.ClientID %>').val(); // gat the value from asp.net form

                        var grouppname = $("#name").val();//get the value from html form
                        var dlg = $(this);


                        $.ajax({
                            async: false,
                            type: "POST",
                            url: "Config.asmx/AddGroup", //asp.net web method AddGroup(int parentid,string gpname)
                            data: JSON.stringify({ parentid: pid, gpname: grouppname }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (data) {
                                var models = data.d;
                                alert('data inserted...')
                                dlg.dialog("close");
                            },
                            complete: function (data) { },
                            error: function (req, status, error) { alert(error.toString()) }
                        })
                    }
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            },
            close: function () {
                allFields.val("").removeClass("ui-state-error");
            }
        });         
于 2012-10-08T11:52:01.090 回答