Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to bind an Autoextender using dynamic context key i mean i've a Drodownlist it has two items PARTY and GROUP and if i select PARTY then only party records should be bound in AutoExtender and if select GROUP then group records should be bound. Everything is running ok even in WebService it is fetching correct records but in AutoExtender it is showing first time selected or brought records.


Here is my code

HTML
<script language="javascript" type="text/javascript">
    function openWin() 
    {
        window.print();
    }
    
    function getContextKey(ddlWise_Client) 
    {
        debugger;
        var ddlWise = document.getElementById(ddlWise_Client);
        var conKey;
    
        if (ddlWise.value == "GROUP") 
        {
            conKey = "GROUP";
        }
        else 
        {
            conKey = "ACM";
        }
    
        var autoComplete = $find('AutoCompleteExtender2');
        autoComplete.set_contextKey(conKey);
    }
</script>

XML
<div>
       <asp:DropDownList ID="ddlWise" TabIndex="2" SkinID="sddlHalf" runat="server">
           <asp:ListItem Selected="True" Text="PARTY" Value="PARTY"></asp:ListItem>
           <asp:ListItem Text="GROUP" Value="GROUP"></asp:ListItem>
       </asp:DropDownList>
       <asp:TextBox ID="txtWise" SkinID="stxtDefault" Width="210px" runat="server"></asp:TextBox>
       <cc1:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" TargetControlID="txtWise"
           ContextKey="ddlWise" ServiceMethod="GetGroupType" ServicePath="~/Webservices/Search.asmx"
           MinimumPrefixLength="1" CompletionInterval="0000" CompletionSetCount="20"
           CompletionListItemCssClass="AutoComplete_CSS1" CompletionListHighlightedItemCssClass="AutoComplete_CSS2"
           UseContextKey="true" CompletionListElementID="divWise" CompletionListCssClass="CompletionListCss">
       </cc1:AutoCompleteExtender>
   </div>

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ddlWise.Attributes.Add("onchange", "return getContextKey('" + ddlWise.ClientID + "')");
            }
        }


 [WebMethod]
    public string[] GetGroupType(string prefixText, int count, string contextKey)
    {
        using (SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()))
        {

            con.Open();

            //string[] conKey = contextKey.Split(',');
            string strsql = string.Empty;

           
            if (contextKey.ToString() == "GROUP")
            {
                strsql = "SELECT DISTINCT Top " + count + " ACG_NAME,ACG_CODE FROM ACCOUNTGROUP WHERE ACG_NAME LIKE " + " '" + prefixText + "%' and ACG_STS_CODE=1";
            }
            else if (contextKey.ToString() == "TYPE")
            {

                strsql = "SELECT DISTINCT Top " + count + " ACT_NAME,ACT_CODE FROM ACCOUNTTYPE WHERE ACT_NAME LIKE " + " '" + prefixText + "%' and ACT_STS_CODE=1";
            }
            else
            {
                strsql = "SELECT DISTINCT Top " + count + " ACM_NAME,ACM_CODE FROM ACM WHERE ACM_NAME LIKE " + " '" + prefixText + "%' and ACM_STS_CODE=1";
            }

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = strsql;
            cmd.CommandType = CommandType.Text;

            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);

            List<string> items = new List<string>(count);            

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //items.Add(dt.Rows[i][0].ToString());
                    items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString()));
                }
            }

            return items.ToArray();
        }
    }</string></string>
Posted
Updated 19-Apr-13 19:14pm
v5
Comments
Hemant Singh Rautela 19-Apr-13 8:45am    
where are your code ... ?? which you applied.
Karthik Harve 20-Apr-13 1:15am    
[Edit] code blocks added with pre tags.
.NET- India 22-Apr-13 8:04am    
I'm not understanding please explain and what should i do
Karthik Harve 22-Apr-13 8:27am    
.NET- India 23-Apr-13 1:02am    
Mr. Karthik, where is to place pre tag. Please explain

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900