我是asp.net中这个jquery对话框的新手。我正在尝试从jquery对话框中打开的dropdownlist中获取所选值。第一个用户将单击一个按钮,将显示一个对话框。在对话框中,用户将在下拉列表中选择项目,当用户单击“确定”时,更新查询将根据下拉列表中的选定值执行。问题是,当用户单击“确定”时,我的表格没有变化。这是我的代码。提前致谢
<script type="text/javascript">
function ShowPopup(message) {
$(function () {
$("#dialog").dialog({
modal: true,
buttons: {
Ok: function () {
$("[id*=btnOKStatus]").click();
},
Close: function () {
$(this).dialog('close');
}
}
});
});
};
</script>
xml
<asp:ImageButton ID="btnUpdateStatus" runat="server"
ImageUrl="~/images/btnUpdateStatus.png" Height="40px" Width="50px"
Style="vertical-align: middle;" BorderStyle="None" OnClick="btnShowPopup_Click" />``
<div id="dialog" style="display: none">
<asp:Label ID="lblDialog" runat="server" Text="Sila pilih status: "></asp:Label><br /><asp:DropDownList
ID="ddlStatus" runat="server">
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Pending</asp:ListItem>
<asp:ListItem>Complete</asp:ListItem> </asp:DropDownList>
</div>
<asp:Button ID="btnOKStatus" runat="server" Text="Button" style =
"display:none" OnClick = "btnOKStatus_Click" />
VB
Protected Sub btnShowPopup_Click(sender As Object, e As System.EventArgs) Handles btnUpdateStatus.Click
Dim message As String = ""
ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "ShowPopup('" + message + "');", True)
End Sub
Protected Sub btnOKStatus_Click(sender As Object, e As EventArgs)
Using mysqlConnection = New MySqlConnection(connStr)
mysqlConnection.Open()
queryStr = "UPDATE `order` SET status=@status WHERE ID=@orderID"
cmd = New MySqlCommand(queryStr, mysqlConnection)
cmd.Parameters.AddWithValue("@orderID", Page.Request.QueryString("orderID").ToString())
cmd.Parameters.AddWithValue("@status", ddlStatus.SelectedValue)
Dim num As Integer = cmd.ExecuteNonQuery()
If num > 0 Then
ClientScript.RegisterStartupScript(Page.[GetType](), "key", "alert('Success!')", True)
Else
ClientScript.RegisterStartupScript(Page.[GetType](), "key", "alert('Fail')", True)
End If
mysqlConnection.Close()
End Using
End Sub
答案 0 :(得分:0)
以下选择器将返回所选值。
$('#ddlStatus > li:selected').val()
然而,这似乎更像是一个ASP.Net问题。如果要在VB.Net代码中获取下拉列表的选定值,可以使用下拉列表中的ID并访问VB.net代码中的下拉列表,
ddlStatus.SelectedValue
尝试更改此
Protected Sub btnOKStatus_Click(sender As Object, e As EventArgs)
Using mysqlConnection = New MySqlConnection(connStr)
mysqlConnection.Open()
queryStr = "UPDATE `order` SET status=@status WHERE ID=@orderID"
cmd = New MySqlCommand(queryStr, mysqlConnection)
cmd.Parameters.AddWithValue("@orderID", Page.Request.QueryString("orderID").ToString())
cmd.Parameters.AddWithValue("@status", ddlStatus.SelectedValue)
Dim num As Integer = cmd.ExecuteNonQuery()
If num > 0 Then
ClientScript.RegisterStartupScript(Page.[GetType](), "key", "alert('Success!')", True)
Else
ClientScript.RegisterStartupScript(Page.[GetType](), "key", "alert('Fail')", True)
End If
mysqlConnection.Close()
End Using
End Sub
到此:
Protected Sub btnOKStatus_Click(sender As Object, e As EventArgs)
If Page.IsPostBack = False Then
Using mysqlConnection = New MySqlConnection(connStr)
mysqlConnection.Open()
queryStr = "UPDATE `order` SET status=@status WHERE ID=@orderID"
cmd = New MySqlCommand(queryStr, mysqlConnection)
cmd.Parameters.AddWithValue("@orderID", Page.Request.QueryString("orderID").ToString())
cmd.Parameters.AddWithValue("@status", ddlStatus.SelectedValue)
Dim num As Integer = cmd.ExecuteNonQuery()
If num > 0 Then
ClientScript.RegisterStartupScript(Page.[GetType](), "key", "alert('Success!')", True)
Else
ClientScript.RegisterStartupScript(Page.[GetType](), "key", "alert('Fail')", True)
End If
mysqlConnection.Close()
End Using
End If
End Sub
答案 1 :(得分:0)
现在为时已晚,但我正在为那些面临类似问题的人(如问题标题中提到)(以及未使用ASP.net的人)发布答案。
var selectedItemText = $("#myselect option:selected" ).text();
var selectedItemCode = $("#myselect option:selected" ).val();