我有Jquery Dialog with dropdown等。点击ok按钮后如何在代码中取这个值?
<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 :(得分: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> <asp:Label ID="lblFrom" Font-Bold="true" runat="server" Text="From: "></asp:Label><asp:Label runat="server" ID="lblSendFrom" Text="Training.Registration@JeffWyler.com"></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)或链接按钮。希望这有帮助!
答案 1 :(得分:0)
您可以简单地对Web服务执行PageMethod调用,以使用所选值执行进程,然后返回true以使回发发生。