Thursday, April 5

AutoComplete TextBox Fetching Name with ID From sqlserver database

This is my screenshot of Total application



My database screenshot




















Overall database View





















I have taken one linq to sql class as well as one wcf web services as Service1.svc


Here is the code of service1.svc.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web.Script.Services;
using System.Text;
using System.Web;
using System.Data.SqlClient;
using System.Web.Services;
using System.Configuration;
using System.Data;


using System.Web.Services.Protocols;


namespace Test
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
   
    public class Service1
    {
        // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
        // To create an operation that returns XML,
        //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
        //     and include the following line in the operation body:
        //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        [OperationContract]
        public void DoWork()
        {
            // Add your operation implementation here
            return;
        }




        
          [OperationContract]
       public string[] TXTSEARCH(string prefixText)
       {
           string[] Array1 = null;
           DataClasses1DataContext d1 = new DataClasses1DataContext();
           var res = (from result in d1.TextboxAutoImpliments
                      where result.Name.ToLower().StartsWith(prefixText.ToLower())
                      select result.Name).Take(10);
           Array1 = res.ToArray();
           return Array1;






       
        
       }
    }
}

Here is my source code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextBoxAutoComplete.aspx.cs" Inherits="Test.LINQInsert" %>

<%@ 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">
<asp:ScriptManager runat="server"></asp:ScriptManager>
    
    
    <table >
        <tr>
            <td  >
                ID</td>
            <td>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    
    
            </td>
        </tr>
        <tr>
            <td>
                Name</td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server" AutoPostBack="True" 
                    ontextchanged="TextBox4_TextChanged"></asp:TextBox>
                <asp:AutoCompleteExtender ID="TextBox4_AutoCompleteExtender" runat="server" 
                    DelimiterCharacters=""
                Enabled="True" MinimumPrefixLength="1"  ServicePath="Service1.svc" ServiceMethod="TXTSEARCH" TargetControlID="TextBox4"></asp:AutoCompleteExtender>
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <p>
        &nbsp;</p>
    <p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;</p>
    </form>
</body>
</html>

Here is my code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Threading;
namespace Test
{
    public partial class LINQInsert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void TextBox4_TextChanged(object sender, EventArgs e)
        {
            DataClasses1DataContext d1 = new DataClasses1DataContext();
            var res = (from result in d1.TextboxAutoImpliments
                       where result.Name.ToLower().StartsWith(TextBox4.Text.ToLower())

                       select new { ID = result.ID }).Take(10);
            foreach (var id in res)
            {
                Label1.Text = id.ToString();
            }
        }
       
        
        
    }
}

After Running It :

























Thanks Shibashish mohanty

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

ShibashishMnty
shibashish mohanty