Saturday, 7 April 2012

autocomplete extender with webservice


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.EnterpriseServices;
using System.Data.EntityModel;
using jayModel;


/*auto complete extender with webservice with edmx*/
public partial class Google : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] HelloWorld(string prefixText, int count)
    {
        // Class1 cs = new Class1();
        WebService ws = new WebService();
        return ws.HelloWorld(prefixText, count);
    }
}
//source file

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Google.aspx.cs" Inherits="Google" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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>
    <%--<script language="javascript" type="text/javascript">

     function mypopup(url, width, height) {
         mywindow = window.open(url, "mywindow2112", "location=0,status=1,scrollbars=1,resizable=1,menubar=0,toolbar=no,width=" + width + ",height=" + height);
         mywindow.focus();
     }

    </script>
    --%>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <table style="width: 104%">
            <tr>
                <td>
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/image/google1.bmp"
                        Width="1330px" />
                </td>
            </tr>
        </table>
    </div>
    <p align="center">
        <asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("name") %>' Wrap="False"
            Height="16px" Width="357px"></asp:TextBox>
        <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
            ServiceMethod="HelloWorld" MinimumPrefixLength="1" UseContextKey="false" CompletionInterval="500"
            EnableCaching="true" CompletionSetCount="12">
        </cc1:AutoCompleteExtender>
    </p>
    <div>
        <table width="100%">
            <tr>
                <td>
                    <asp:Image ID="Image2" runat="server" ImageUrl="~/image/google2.bmp"
                        Width="1330px" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
//web service

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.EnterpriseServices;
using System.Data.EntityModel;
using jayModel;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
    jayEntities j = new jayEntities();
    Table1 t = new Table1();
    public WebService () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
 
    public string[] HelloWorld(string prefix, int count)
    {
        var a = j.Table1.Where(f => f.name.StartsWith(prefix)).Select(f => f.name).ToArray();

        return a;



    }
   
}


No comments:

Post a Comment