автозаполнение текстового поля с использованием интерфейса jquery в vb.net - PullRequest
0 голосов
/ 07 июня 2011

Я использую два автозаполнения в моей форме, используя 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

1 Ответ

0 голосов
/ 26 июля 2011

Вы хотите установить параметр extraParam, например:

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

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

Если вам нужно, чтобы значения были каскадными, вам нужно установить обработчик выбора для родительского элемента, чтобы сохранить выбранное значение в замыкании или где-то на странице. (если значение не является тем, что пользователь ввел / выбрал, в этом случае вы можете просто взять его оттуда.) U

...