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
<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>
<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>
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 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(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString()));
}
}
return items.ToArray();
}
}</string></string>