borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2011 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Why to stop development of VB)Next Topic (ASP.NET 3.5 Interview Questions, faqs, ebooks (PDF)) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : AutoComplete TextBox using AjaxToolkit
Poster Message
Afshin_Zavar
Level: Professor


Registered: 17-07-2003
Posts: 74

icon AutoComplete TextBox using AjaxToolkit

What's wrong with my code ?!


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
       </asp:ToolkitScriptManager>
       <asp:TextBox ID="txtMovie" runat="server"></asp:TextBox>
        
       <asp:AutoCompleteExtender
       ID="AutoCompleteExtender1"
       runat="server"
       TargetControlID="txtmovie"
       ServicePath="AutoComplete.asmx"
       ServiceMethod="GetProducts"
       MinimumPrefixLength="2"
       EnableCaching="false">
    </asp:AutoCompleteExtender>
    
     </div>
    
    </form>
</body>
</html>

and

using System.Collections;&#8233;
using System.Web.Services;
&#8233;using System.Web.Services.Protocols;
&#8233;using System.Data;
using System.Data.SqlClient;&#8233;
using System.Configuration;&#8233;&#8233;
namespace WebApplication1
&#8233;{&#8233;  
[WebService(Namespace = "http://tempuri.org/")]&#8233;
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]&#8233;
  [System.ComponentModel.ToolboxItem(false)]&#8233;
public class AutoComplete : System.Web.Services.WebService&#8233;
{
[System.Web.Services.WebMethod]&#8233;
[System.Web.Script.Services.ScriptMethod]&#8233;  
public string[] GetProducts(string prefixText)&#8233;
{&#8233;
SqlConnection cnn = new SqlConnection(@"Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=123");&#8233;
string sql = "Select * from [products] Where [ProductName] Like @prefixText";
  SqlDataAdapter da = new SqlDataAdapter(sql, cnn);&#8233;
  da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";&#8233;
  DataTable dt = new DataTable();&#8233;
  da.Fill(dt);&#8233;
  string[] items = new string[dt.Rows.Count];&#8233;
  int i = 0;&#8233;
  foreach (DataRow dr in dt.Rows)
  {&#8233;
    items.SetValue(dr["ProductName"].ToString(), i);&#8233;
    i++;&#8233;        
  }&#8233;        
  return items;&#8233;
  }&#8233;    }&#8233;}&#8233;


[Edited by Afshin_Zavar on 30-07-2010 at 06:08 PM GMT]

____________________________
Persia

30-07-2010 at 06:06 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : ASP.Net : AutoComplete TextBox using AjaxToolkit
Previous Topic (Why to stop development of VB)Next Topic (ASP.NET 3.5 Interview Questions, faqs, ebooks (PDF)) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2011 Andrea Tincaniborder