This is a migrated thread and some comments may be shown as answers.

Select an item

2 Answers 34 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Sonia
Top achievements
Rank 1
Sonia asked on 17 Oct 2013, 08:11 AM
Hi,

How can i select an item in javascript?

Thank you,
Sonia.

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 17 Oct 2013, 10:27 AM
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.
0
Sonia
Top achievements
Rank 1
answered on 17 Oct 2013, 10:36 AM
Thank you Princy,

This was exactly what i needed.
Tags
DropDownList
Asked by
Sonia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Sonia
Top achievements
Rank 1
Share this question
or