0

我使用 jQuery 在我的表单中使用了两个自动完成扩展器。我想将一个自动完成扩展器的值传递给另一个自动完成扩展器。请让我知道如何使用 jQuery 传递值。

我的 VB.net 页面:-

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="jquery/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="jquery/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function() {
        $("#txtSearch").autocomplete('Search_Scheme.ashx');
    }); 

    $(document).ready(function() {
        $("#txtProperty").autocomplete('Search_Property.ashx');
    });

</script> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table cellspacing="0" cellpadding="0" align="center" border="0" style="text-align: left" width="95%">
            <tr>
                <td align="center" bgColor="#ffffff" style="width: 50%;"> 
                    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
                </td>

                <td align="center" bgColor="#ffffff" style="width: 50%;"> 
                    <asp:TextBox ID="txtProperty" runat="server"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

我的 txtSearch 文本框类:-

<%@ WebHandler Language="VB" Class="Search_Scheme" %>

Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.OleDb

Public Class Search_Scheme : Implements IHttpHandler
    Implements SessionState.IRequiresSessionState

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim SQL As String = ""
        Dim Con As New DbConnection
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader

        Dim prefixText As String = context.Request.QueryString("q")
        Dim sb As StringBuilder = New StringBuilder

        SQL = " Select Scheme_Name,Scheme_Id from Scheme_Definition" & _
              " Where Org_Id ='" & context.Session("OrgId") & "'"
        If prefixText <> "" Then
            SQL &= " and upper(scheme_Name) like '%" & prefixText.Trim().ToUpper().Replace("'", "''") & "%'"
        End If
        SQL &= " Order By Scheme_Name"

        Con.Connect()
        cmd = New OleDbCommand(SQL, Con.Con)
        dr = cmd.ExecuteReader()

        While dr.Read()
            sb.Append(dr("Scheme_Name")) _
                .Append(Environment.NewLine)
        End While
        dr.Close()
        cmd.Cancel()
        cmd.Dispose()
        Con.DisConnect()

        context.Response.Write(sb.ToString)
    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
End Class

我的 txtProperty 文本框类:-

<%@ WebHandler Language="VB" Class="Search_Property" %>

Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.OleDb

Public Class Search_Property : Implements IHttpHandler
    Implements SessionState.IRequiresSessionState

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim SQL As String = ""
        Dim Con As New DbConnection
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader


        Con.Connect()

        Dim prefixText As String = context.Request.QueryString("q")
        Dim sb As StringBuilder = New StringBuilder

        Dim tSchemeId As Integer = 0

        Dim myString As String = System.Web.HttpContext.Current.Request.QueryString("country")

        SQL = " SELECT SCHEME_ID FROM SCHEME_DEFINITION" & _
              " WHERE ORG_ID ='" & context.Session("OrgId") & "'" & _
              " AND UPPER(SCHEME_NAME) ='---Here text of txtSearch textBox----'"

        '---Here i am not able to pass either scheme_id  or scheme_name--- Please Help....

        cmd = New OleDbCommand(SQL, Con.Con)
        tSchemeId = CInt(cmd.ExecuteScalar())
        cmd.Cancel()
        cmd.Dispose()

        'tSchemeId = 8


        SQL = " SELECT PROPERTY_ID as PROPERTY_ID,PROPERTY_NAME" & _
              " FROM PROPERTIES" & _
              " WHERE SCHEME_ID ='" & tSchemeId & "'" & _
              " ORDER BY PROPERTY_NAME"

        'MsgBox(SQL)

        cmd = New OleDbCommand(SQL, Con.Con)
        dr = cmd.ExecuteReader()

        While dr.Read()
            sb.Append(dr("PROPERTY_NAME")) _
                .Append(Environment.NewLine)
        End While
        dr.Close()
        cmd.Cancel()
        cmd.Dispose()
        Con.DisConnect()

        context.Response.Write(sb.ToString)
    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
End Class
4

1 回答 1

0

您想设置 extraParam 选项,如下所示:

$("#txtProperty").autocomplete('Search_Property.ashx', { extraParams: { scheme_id: 2271 } });

见: http ://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions

如果您需要级联值,则必须在父级上设置一个选择处理程序,以将所选值存储在闭包中或页面上的某个位置。(除非该值是用户键入/选择的值,在这种情况下,您可以从那里获取它。)U

于 2011-07-25T23:17:44.620 回答