Showing posts with label AUTOCOMPLETE EXTENDER VALUE IN TEXTBOX BASED ON DROPDOWNLIST VALUE. Show all posts
Showing posts with label AUTOCOMPLETE EXTENDER VALUE IN TEXTBOX BASED ON DROPDOWNLIST VALUE. Show all posts

Thursday 9 February 2012

AUTOCOMPLETE EXTENDER VALUE IN TEXTBOX BASED ON DROPDOWNLIST VALUE


AUTOCOMPLETE EXTENDER VALUE IN TEXTBOX BASED ON DROPDOWNLIST VALUE








.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
        <style>
        .autocomplete_completionListElement
        {
            visibility: hidden;
            margin: 0px !important;
            background-color: inherit;
            color: windowtext;
            border: buttonshadow;
            border-width: 1px;
            border-style: solid;
            cursor: 'default';
            overflow: auto;
            height: 200px;
            text-align: left;
            list-style-type: none;
            font-family: courier new;
            font-size: 8pt;
        }
        /* AutoComplete highlighted item */.autocomplete_highlightedListItem
        {
            background-color: #e3ec6e;
            color: black;
            padding: 1px;
        }
        /* AutoComplete item */.autocomplete_listItem
        {
            background-color: window;
            color: windowtext;
            padding: 1px;
        }
        body, div, p, h1, h2, h3, h4, ul, li, table
        {
            margin: 0;
            padding: 0;
            border: none;
 
        }
    </style>
</head>
<script type="text/javascript">


</script>
<body>
    <form id="form1" runat="server">
        <cc1:autocompleteextender id="AutoCompleteExtender1" runat="server" minimumprefixlength="1"
            servicemethod="GetCountryInfo" servicepath="WebService.asmx"  TargetControlID="TextBox1">
           
            </cc1:autocompleteextender>
        <asp:TextBox ID="TextBox1" runat="server" Width="381px"></asp:TextBox>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <br />
     
      <cc1:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"
      CompletionListItemCssClass="autocomplete_listItem"  MinimumPrefixLength="1"
      ServiceMethod="GetCountryOrStatesInfo" UseContextKey="true" ContextKey="salem"
      ServicePath="WebService.asmx" TargetControlID="TextBox2" EnableCaching="true" Enabled="true" ></cc1:AutoCompleteExtender>
        <br />
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server" Width="431px"></asp:TextBox>
     <asp:DropDownList ID="cmbList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="cmbList_SelectedIndexChanged" DataSourceID="SqlDataSource1" DataTextField="city_name" DataValueField="city_name"> </asp:DropDownList><asp:SqlDataSource
         ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:flywindzConnectionString %>"
         SelectCommand="SELECT DISTINCT [city_name] FROM [city_master]"></asp:SqlDataSource>
    
    
    
    
     
    
    
    
    </form>
</body>
</html>

.cs file

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {


            AutoCompleteExtender2.ContextKey = "Salem";


        }

    }
   
    protected void cmbList_SelectedIndexChanged(object sender, EventArgs e)
    {
      
        AutoCompleteExtender2.ContextKey = cmbList.SelectedValue;
    }
using System;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data;


/// <summary>
/// Summary description for WebService
/// </summary>
[System.Web.Script.Services.ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

    [WebMethod]
    public string[] GetCountryInfo(string prefixText)
    {
        int count = 10;
        string sql = "select * from client_master where client_name like @prefixText";
        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
        DataTable dt = new DataTable();

        da.Fill(dt);
        string[] items = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            items.SetValue(dr["client_name"].ToString(), i);
            i++;

        }
        return items;
    }



[WebMethod] public string[] GetCountryOrStatesInfo(string prefixText, string contextKey)
{
  int count = 10;
  string sql=null;

      sql = "select Client_name +','+ client_city as [client_name]  from client_master where client_name like @prefixText and client_city='" + contextKey + "'";
 
  SqlDataAdapter da = new SqlDataAdapter(sql,conn);
  da.SelectCommand.Parameters.Add("@prefixText",SqlDbType.VarChar, 50).Value = prefixText + "%";
  DataTable dt = new DataTable();
  da.Fill(dt);

  string[] items = new string[dt.Rows.Count];
  int i = 0;
  foreach (DataRow dr in dt.Rows)
  {
    items.SetValue(dr[0].ToString(), i);
    i++;
  
  }

    return items;
}

 
   
}