Select an item

3 posts, 1 answers
  1. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 17 Oct 2013 Link to this post

    Hi,

    How can i select an item in javascript?

    Thank you,
    Sonia.

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Oct 2013 Link to this post

    Hi Sonia,

    Please try the following code snippet that I tried to set an item as selected in JavaScript.

    ASPX:
    <telerik:RadDropDownList ID="RadDropDownList1" runat="server" DataSourceID="SqlDataSource1"
        DefaultMessage="select" DataTextField="Cityname" AutoPostBack="true">
    </telerik:RadDropDownList>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Set Item" OnClientClicked="OnClientClicked">
    </telerik:RadButton>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [Cityname] FROM [City]">
    </asp:SqlDataSource>

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked(sender, args) {
            var dropdownlist = $find("<%=RadDropDownList1.ClientID %>");
            dropdownlist.findItemByText("Chennai").set_selected(true);
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 17 Oct 2013 Link to this post

    Thank you Princy,

    This was exactly what i needed.
Back to Top