2013-12-09 53 views
0

我有jquery對話框與下拉列表等。我怎樣才能把這個值在代碼後點擊ok按鈕後?jquery對話框網表格

<script type="text/javascript"> 
    $(function() { 

     $("#dialog").dialog({ 
      height: 600, 
      width: 900, 
      modal: true, 
      autoOpen: false, 
      show: { 
       effect: "blind", 
       duration: 1000 
      }, 
      hide: { 
       effect: "blind", 
       duration: 1000 
      }, 

      buttons: { 
       Ok: function() { 


        //want a dropdown selected item value so that i can use in the code behind and perform some query on that 

        $("[id*=btnLoadGrid]").click(); //doing postback for the server side button and loading dialog again.. 

       }, 
       Close: function() { 
        $(this).dialog('close'); 
       } 

      } 

     }); 

     $("[id$=opener]").click(function() { 
      $("#dialog").dialog("open"); 
     }); 

    }); 

</script> 

基本上我想要的下拉值在代碼中使用後面的查詢和代碼再次重新加載對話框後面。

所以我的隱藏文件的代碼是...

Protected Sub btnLoadGrid_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLoadGrid.Click 

    Dim stats As String = "Here I want the status value from dropdown" 


    Dim connectionstring As String = ConfigurationManager.ConnectionStrings("DbConn").ToString 
    'Dim objconnection As SqlConnection = New SqlConnection 
    Using objconnection As New SqlConnection(connectionstring) 

     'Dim sqlDs As SqlDataSource = New SqlDataSource() 

     Dim Query As String = "Select top 5 ROW_NUMBER()over(order by Division,Name,NoOfDays) as [SR.No],Division,Name,Name,start_Date,End_Date,NoOfDays from emp_progm" 
     Query &= " where status= '" & stats & "'" 
     'sqlDs.SelectCommand = Query 

     Dim cmd As New SqlCommand(Query, objconnection) 
     Dim da As New SqlDataAdapter(cmd) 
     Dim ds As New DataSet() 
     da.Fill(ds) 
     GridView1.DataSource = ds 
     GridView1.DataBind() 


    End Using 

發射查詢

Dim script As String = "$(document).ready(function() { $('[id*=opener]').click(); });" 
    ClientScript.RegisterStartupScript(Me.GetType, "load", script, True) 

End Sub 
+0

向我們展示你的'.dialog()'代碼,我們可以給你一個關於你可以在哪裏使用AJAX的提示。 – MonkeyZeus

回答

1

這是我該怎麼辦煤礦後重裝電網。這是一個工作示例,就像我發送電子郵件一樣,原理相同,只是不同的代碼。

jQuery的

function sendEmail() { 
    $("#email").dialog({ 
     modal: true, 
     width: 550, 
     buttons: { 
      "Send": function() { 
       var btn = document.getElementById("<%=lbSend.ClientID %>"); 
       if (btn) btn.click(); 
       $(this).dialog("close"); 
      }, 
      Cancel: function() { 
       $(this).dialog("close"); 
      } 
      } 
     }); 
     jQuery("#email").parent().appendTo(jQuery("form:first"));//this is key as it makes sure it finds the textboxes within the dialog. Without this, you will insert blank values. 
     } 

ASP

<div class="popUpStyle" title="Send Email" id="email" style="display: none"> 
    <asp:Label ID="lblTo" runat="server" Text="To: " Font-Bold="true"></asp:Label><asp:Label runat="server" ID="lblSendTo" Text=""></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="lblFrom" Font-Bold="true" runat="server" Text="From: "></asp:Label><asp:Label runat="server" ID="lblSendFrom" Text="[email protected]"></asp:Label> 
    <br /> 
    <asp:Label ID="lblSubject" Font-Bold="true" runat="server" Text="Subject: "></asp:Label><asp:TextBox ID="tbSubject" runat="server" Width="200px"></asp:TextBox> 
    <br /> 
     <asp:Label ID="lblBody" Font-Bold="true" runat="server" Text="Message:"></asp:Label> 
    <br /> 
    <asp:TextBox ID="tbMessage" runat="server" Width="515px" TextMode="MultiLine" Height="150px"></asp:TextBox> 
    <asp:LinkButton ID="lbSend" runat="server" Text="" Width="50px" Font-Size="smaller" OnClick="lbSend_Click"></asp:LinkButton> 
</div> 

代碼隱藏C#

protected void lbSend_Click(object sender, EventArgs e) 
{ 
    //code to your database 
} 

在ASP標記,我有一個可見的鏈接按鈕,但文本沒有顯示。 (將鏈接按鈕設置爲visible = false會觸發按鈕)我使用對話框按鈕調用鏈接按鈕的命令。如果你不想對話按鈕,你可以簡單地有按鈕(確保你設置提交行爲爲false)或鏈接按鈕。希望這可以幫助!

0

您可以簡單地對Web Service執行PageMethod調用,以執行具有選定值的進程,然後返回true以使回發發生。