开发者

auto complete textbox using jquery UI in vb.net

I am using two autocomplete extenders in my form using jQuery. I want to pass the value of one autocomplete extender to another autocomplete extender. Please let me know how can I pass value using jQuery.

My VB.net page :-

<%@ 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>

My Class for txtSearch textbox:-

<%@ 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开发者_JS百科 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

My Class for txtProperty textbox:-

<%@ 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


You want to set the extraParam option, as in:

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

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

If you need the values to be cascading, you'll have to set a select handler on the parent to store the selected value in a closure or somewhere on the page. (unless the value is what the user typed/selected, in which case you can just grab it from there.) U

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜