• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Need to get index of item in AutoCompleteExtender

I am just starting out in ajax.  I've figured out how to get the items I need to fill a list in the AutoExtendControl attached to a textbox.  That part works fine, and I'm able to enter text, see the drop-down, and then select an item to fill out the textbox.  But I am trying to find a quick way to access the index (integer) of the item selected from the list.  I need this in order to search a separate list for the same index in order to pull values into other places on the page.  
1 Solution
1: add hidden field next to your serach textbox
                    <asp:HiddenField ID="SelectedItemValue" runat="server" />
2: register onchange event to your listbox
                     listbox.Attributes.Add("onchange", String.Format("javascript:SelectItem(this,  '{0}');", SelectedItemValue.ClientID);
3: Create a javascript function where you copy the listbox selected value into the hidden field.
                     function SelectItem(listElement, hdnField)
                        document.getElementById(hdnField).value = listElement.options[listElement.selectedIndex].value

then you should have the selected value in hidden field for later use.

Hope this helps!
RinaXAuthor Commented:

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now