I have the following ASP.NET RadioButtonList:
<asp:RadioButtonList ID="rbl" runat="server">
<asp:ListItem Text="Type1" Value="1" />
<asp:ListItem Text="Type2" Value="2" />
</asp:RadioButtonList>
I would like to select an item in the list programmatically via a client-side jquery function like this (simplified version):
function BindWidget(widget) {
// Type property of Widget is an int.
$("#<%=rbl.ClientID%>").selectItemByValue(widget.Type);
}
Ideally, there is some function - in the above code I have proposed selectItemByValue - that selects an item in a RadioButtonList by a given value. Does jquery have a similar function built-in? If not, how should I go about implementing the desired functionality?
try this.
$('#<%=rbl.ClientID %>').find("input[value=" + widget.Type + "]").attr("checked", "checked");