1) create data source as List<string>();
List<string> custList = new List<string>();
string custItem = string.Empty;
while (dr.Read())
{
custItem=AutoCompleteExtender.CreateAutoCompleteItem(dr[0].ToString(),dr[1].ToString());
custList.Add(custItem);
}
string custItem = string.Empty;
while (dr.Read())
{
custItem=AutoCompleteExtender.CreateAutoCompleteItem(dr[0].ToString(),dr[1].ToString());
custList.Add(custItem);
}
2)In the Asp.net page
<script type="text/javascript">
function ace1_itemSelected(sender, e)
{
var hdCustID = $get('<%= hdEmpID.ClientID %>');
hdCustID.value = e.get_value();
}
</script>
<asp:TextBox ID="txtEmpName" AutoPostBack="true" AutoComplete="off" runat="server"
OnTextChanged="txtEmpName_TextChanged" />
<cc1:AutoCompleteExtender ID="ace1" TargetControlID="txtEmpName" ServiceMethod="GetSuggestions"
MinimumPrefixLength="1" OnClientItemSelected="ace1_itemSelected" FirstRowSelected="true"
runat="server" />
<asp:HiddenField ID="hdEmpID" runat="server" />
function ace1_itemSelected(sender, e)
{
var hdCustID = $get('<%= hdEmpID.ClientID %>');
hdCustID.value = e.get_value();
}
</script>
<asp:TextBox ID="txtEmpName" AutoPostBack="true" AutoComplete="off" runat="server"
OnTextChanged="txtEmpName_TextChanged" />
<cc1:AutoCompleteExtender ID="ace1" TargetControlID="txtEmpName" ServiceMethod="GetSuggestions"
MinimumPrefixLength="1" OnClientItemSelected="ace1_itemSelected" FirstRowSelected="true"
runat="server" />
<asp:HiddenField ID="hdEmpID" runat="server" />
3) the the code behind
String selectedEmpID = hdEmpID.Value;
Thats it!
Ref: http://forums.asp.net/t/1608031.aspx/1?AutoCompleteExtender+Selected+Value+Feature
No comments:
Post a Comment