Live Chat Icon For mobile
Live Chat Icon

How to select all the Items from a listbox when the user selects a radio button

Platform: ASP.NET| Category: ListBox

<asp:listbox id='ListBox1' runat='server' selectionmode='Multiple'>
	<asp:listitem value='Red'>Red</asp:listitem>
	<asp:listitem value='Blue'>Blue</asp:listitem>
	<asp:listitem value='Green'>Green</asp:listitem>
	<asp:listitem value='White'>White</asp:listitem>
</asp:listbox>
<asp:radiobutton id='RadioButton1' runat='server' groupname='selrb' text='Select All' autopostback='True'></asp:radiobutton>

VB.NET


Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
	        Dim lstItem As ListItem
	        For Each lstItem In ListBox1.Items
		            lstItem.Selected = True
	        Next
    End Sub

C#


foreach (ListItem lstItem in ListBox1.Items)
{
	lstItem.Selected = true; 
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.