Search code examples
javascriptasp.nettelerik

Is it possible to set the selected value in a Telerik RadDropDownList in Javascript?


Is it possible to set the selected value/item in a Telerik RadDropDownList in Javascript?

I'm looking at the documentation http://www.telerik.com/help/aspnet-ajax/dropdownlist-clientsideprogramming-clientsidebasic.html and it seems there is no documented way to do this simple and essential task.

Is it simply not in the documentation? Tried searching the forums as well to no avail.


Solution

  • You can use select() or set_selected(true) function. Here is the documentation.

    <telerik:RadDropDownList ID="RadDropDownList1" runat="server">
        <Items>
            <telerik:DropDownListItem runat="server" Text="One" Value="1" />
            <telerik:DropDownListItem runat="server" Text="Two" Value="2" />
            <telerik:DropDownListItem runat="server" Text="Three" Value="3" />
        </Items>
    </telerik:RadDropDownList>
    <script type="text/javascript">
        function pageLoad() {
            var dropdownlist = $find("<%= RadDropDownList1.ClientID %>");
            var item = dropdownlist.findItemByValue("3");
            item.select();
        }
    </script>