question

Dikshadudi-8186 avatar image
0 Votes"
Dikshadudi-8186 asked ZhiLv-MSFT edited

how to make radiobuttion visible false in repeater?

I am having 5 radio button in repeater and want to make it invisible when its text is nothing, but it is not working

aspx code:


193470-screenshot-63.png193591-screenshot-64.png193527-screenshot-65.png


vb.net code:

 Imports System.Data
 Imports System.Data.SqlClient
    
 Partial Class Product_detailpage
     Inherits System.Web.UI.Page
    
     Dim user_id As Integer
    
     Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    
         
           
         If Not Me.IsPostBack Then
             Me.pDetailsurl()
             Me.pincode()
             Me.prod_size()
    
         End If
     End Sub
    
     Private Sub prod_size()
         Dim value As String = ""
    
    
         For Each item As RepeaterItem In durl.Items
    
             If item.ItemType = ListItemType.AlternatingItem OrElse item.ItemType = ListItemType.Item Then
                 Dim rdb As RadioButton = TryCast(item.FindControl("RadioButton1"), RadioButton)
                 Dim rdb1 As RadioButton = TryCast(item.FindControl("RadioButton2"), RadioButton)
                 Dim rdb2 As RadioButton = TryCast(item.FindControl("RadioButton3"), RadioButton)
                 Dim rdb3 As RadioButton = TryCast(item.FindControl("RadioButton4"), RadioButton)
                 Dim rdb4 As RadioButton = TryCast(item.FindControl("RadioButton5"), RadioButton)
    
                 If rdb.Text Is Nothing Then
                     MsgBox("hyy")
                     rdb.Visible = False
                 End If
                 If rdb1.Text Is Nothing Then
                     rdb1.Visible = False
                 End If
                 If rdb2.Text Is Nothing Then
                     rdb2.Visible = False
                 End If
                 If rdb3.Text Is Nothing Then
                     rdb3.Visible = False
                 End If
                 If rdb4.Text Is Nothing Then
                     rdb4.Visible = False
                 End If
    
             End If
    
    
         Next
     End Sub

output:

193500-screenshot-66.png


dotnet-aspnet-generaldotnet-aspnet-webformsdotnet-aspnet-webpages
screenshot-63.png (238.6 KiB)
screenshot-64.png (239.3 KiB)
screenshot-65.png (254.3 KiB)
screenshot-66.png (566.1 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Try this:

  If rdb4.Text = "" then


The text is not "nothing" or a so called empty object, but when not set, will become a empty string.

And as noted, you would be better to use a RadioButtonList, since it can be feed data for your selections.

So, if you add a different size etc, then you can feed it a data table of choices. And thus no hard coding in the markup. the RadioButton list is like a drop down, or any other data aware control - you can feed it data, and thus the options will not appear. and a huge bonus feature is that it automatic only allows one selection - you don't have to add any code to de-select the other choices.

But, never the less - you need to check for a empty string - the "text" property will and does exist - even when not set, and since that property exists, then it return is a empty string such as "", and nothing test will not work.

1 Vote 1 ·

Ok thank you for the reply, i already tried this after that it worked.

0 Votes 0 ·

I recommend following standard Web Forms programming practices and bind a radio button list to a data set; data driven design.. Then only the items in the data set are displayed.

Keep in mind, VB.NET and Web Forms are not the best choice for learning web development unless you are planning to support legacy systems. You might want to look into .NET Core.

0 Votes 0 ·

Ok thank you

0 Votes 0 ·

0 Answers