Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery select item in radiobuttonlist via client-side function

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?

like image 806
mcliedtk Avatar asked Mar 06 '26 23:03

mcliedtk


1 Answers

try this.

$('#<%=rbl.ClientID %>').find("input[value=" + widget.Type + "]").attr("checked", "checked");
like image 191
SoftwareGeek Avatar answered Mar 09 '26 16:03

SoftwareGeek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!