2012-10-08 34 views
0

我想使用jQuery對話框WIDGET在我的SQL Server數據庫中插入數據。在jQuery小部件中,我有多個字段和一個提交按鈕,如果用戶按提交,記錄將被輸入到數據庫中,對話框會自動關閉。 Reference Link的代碼可以幫助很多,但我想將它插入到我的數據庫中。請讓我通過這個問題,我真的堅持了這從幾天。我甚至不具有示例代碼張貼在這裏,但我已經做了,直到爲:在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> 
+0

上面顯示的代碼只顯示一個按鈕,但假設我將在對話框和提交按鈕上有多個輸入文件。另一個我忘記提到的問題是,我該如何將一個文本框字段添加到對話框中。 –

+0

你能否提一下你已經寫過的更多的代碼/標記。您提供的引用鏈接具有模態形式的jq對話框,其中包含文本字段以及驗證,您是否仍然在向對話框添加文本框時遇到問題? – Rohit416

+0

這是一個ASP.NET MVC應用程序嗎?是否有限制,您至少不能使用*** MVC的Web API部分?你需要能夠使用4.0框架。 –

回答

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"); 
      } 
     });