jayz jayz - 5 months ago 16
Vb.net Question

Change visibility of RadioButton item from code behind VB.NET

I have a

ASP.NET radiobutton
in my aspx web page and I'm using VB as my programming language.

<asp:RadioButtonList ID="rdoRecStatus" runat="server" Width="152px" CssClass="normalText"
RepeatDirection="Horizontal">
<asp:ListItem Value="1">Open</asp:ListItem>
<asp:ListItem Value="0">Closed</asp:ListItem>
</asp:RadioButtonList>


I want to change the visibility of the 2nd radio button <
asp:ListItem Value="0">Closed</asp:ListItem>
from a button click.

I tried using
rdoRecStatus.Items[1].Visible = True/False
to the above task and it shows an error.

Con you please tell me the right way to do the above task in
VB.NET
. Thank you in advance.

Answer

Unfortunately There is no Visible properties for <asp:ListItem>, So we need to Look for some alternatives here to achieve this target.

Method 1 : Depend css to do this function like the following

 rdoRecStatus.Items(1).Attributes.Add( "hidden", "hidden" )

Method 2 : Remove that particular Item From the List:

 rdoRecStatus.Items.RemoveAt(1)
Comments