Friday, 31 May 2013

Autocompliet pass two value and return a value

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 <script type="text/javascript">
      function pageLoad(sender, e) {
          var o = $find("AutoCompleteExtender2");
          o.add_populating(function () {
              o.set_contextKey($get("<%=txtlocationName.ClientID %>").value);
          });
      }
        </script>


 <asp:TextBox ID="txtlocationName" ValidationGroup="vgsearch" runat="server" onkeyup="1"></asp:TextBox>
<asp:TextBox ID="txtpincode" ValidationGroup="vgsearch"  runat="server" onkeyup="1"></asp:TextBox>
           <asp:AutoCompleteExtender runat="server" ID="AutoCompleteExtender2" TargetControlID="txtpincode"
                UseContextKey="true" ContextKey="txtlocationName" ServicePath="AutoComplete.asmx"
                ServiceMethod="RetrivePincodeList" MinimumPrefixLength="1" EnableCaching="true"
                CompletionListCssClass="Extender" CompletionListItemCssClass="ExtenderList" CompletionListHighlightedItemCssClass="Highlight"
                CompletionListElementID="width" />

 [WebMethod]
    public string[] RetrivePincodeList(string prefixText, string contextKey)
    {
        DataSet ds = new DataSet();
        SqlHelper sqlhelp = new SqlHelper();
        ds = GetPincodfilterbylocationlist(prefixText,contextKey);
        List<string> Pincodelist = new List<string>();
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            Pincodelist.Add(ds.Tables[0].Rows[i]["pincode"].ToString());
        }
        return Pincodelist.ToArray();
    }
    protected DataSet GetPincodfilterbylocationlist(string prefixText, string contextKey)
    {
        SqlHelper sqlhelp = new SqlHelper();
        try
        {
            DataSet ctds = new DataSet();
            object[] obj = new object[13];
            obj[0] = "getpincolist";
            obj[3] = contextKey;
            ctds = SqlHelper.ExecuteDataset(sqlhelp.Connection, "sp_Tab_Employeedetails", obj);
            return ctds;
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }

No comments:

Post a Comment