DataList.SelectedValue Property (System.Web.UI.WebControls) | Microsoft Docs Skip to main content If you leave value empty (or if you backspace the current value), you'll see the other possibilities show up.
It’s a pretty simple, and fairly slick way to do auto-complete on an input text box (as long as your list isn’t too long, since all items will be rendered into the HTML of the page).But I found myself running into a problem: how do I get a numeric or other ID out of the selected option, when I am showing a human-friendly code or description as the value?The DataList has a collection of Option tags with a value, and you can provide a description (though I don’t know if this is part of the standard or not). Once you have the selected option, you can use the .data() method to retrieve the data-attribute in question:If you run this code on the “input” event of the input box, you’ll get the data-id of the selected option as soon as an option is selected – whether it is selected by mouse, arrow keys on the keyboard, or by typing in the complete item value.Note that you do need to account for a selected option not being found, because each time you change the selected value, the “input” event will trigger. The