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 tag specifies a list of pre-defined options for an element.. Definition and Usage. You can reach Derick at DerickBailey.com or on twitter, @derickbailey. This tends to create all kinds of havoc and chaos in the jQuery selector.This is a screenshot from one of my actual projects – typing any special characters or quotes would cause this error to be triggered by the jQuery selector not being able to parse things correctly.I haven’t found a solution for this, with the jQuery selector yet, but there’s probably something simple to prevent this from happening.I’ve generally found the DataList to be a useful component of HTML5, and have almost replaced all of my previous AJAX-style auto-complete situations.There’s less code involved, since the list is stored in the HTML directly, but there are some limitations to this.

He's been a professional developer since the late 90’s, and has been writing code since the late 80’s. Instead, I started using the HTML5 DataList feature. Instead, you only get the value that was specified for the option.To get the data-id out of the option, some slightly clever jQuery can be employed.Assuming you have a unique list of option values, you can find the selected option by using a bit of jQuery. Derick has built software for organizations of all shapes and sizes, including contributions to Microsoft's MDSN library, running several very highly regarded open source projects, creating software solutions for large financial organizations, healthcare orgnaizations, world-class airlines, the U.S. government, and more. Users will see a drop-down list of pre-defined options as they input data. Return Value: An HTMLCollection Object, representing all