Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default9.aspx.vb" Inherits="Default9" %>
<!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>
<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<link href="Styles/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.autocomplete.js" type="text/javascript"></script>
<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="js/jquery.autocomplete.js" type="text/javascript"></script>
<script src="js/jquery.maskedinput-1.3.js" type="text/javascript"></script>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
</form>
</body>
</html>
Default.aspx.vb
Partial Class Default9
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For i As Integer = 0 To 4
Dim txtSearch As New TextBox()
txtSearch.ID = "txtSearch" & i.ToString()
Dim scriptText As [String] = "<script type='text/javascript'> $(document).ready(function () { $(""#txtSearch" & i.ToString() & """).autocomplete('autocomplete.ashx').result(function (event, data, formatted) { if (data) { alert(data[1]); } }); }); </script>"
Page.ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script" & i.ToString(), scriptText)
Panel1.Controls.Add(txtSearch)
Next
End Sub
End Class
autocomplete.ashx
<%@ WebHandler Language="VB" Class="autocomplete" %>
Imports System.Web
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Web.SessionState
Public Class autocomplete
Implements IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim name As String
Dim id As String
Dim prefixText As String = context.Request.QueryString("q")
Dim conn As SqlConnection = New SqlConnection
conn.ConnectionString = ConfigurationManager.ConnectionStrings("SurgereConnection").ConnectionString
Dim stbuilder As StringBuilder = New StringBuilder
stbuilder.Clear()
stbuilder.Append(("select * from Tbl_SampleNames where Name LIKE '" _
+ (prefixText + "%'")))
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = stbuilder.ToString
cmd.Connection = conn
Dim sb As StringBuilder = New StringBuilder
conn.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader
While sdr.Read
name = sdr("Name").ToString
id = sdr("NameId").ToString
sb.Append(String.Format("{0}|{1}|{2}", name, id, Environment.NewLine))
' sb.Append(sdr("Supplier_name").ToString & "-" & sdr("Location_name").ToString) _
' .Append(Environment.NewLine)
End While
conn.Close()
If (sb.ToString <> "") Then
context.Response.Write(sb.ToString)
Else
context.Response.Write("Not available..")
End If
End Sub
ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
No comments:
Post a Comment