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
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
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.
Ok thank you
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.
Ok thank you for the reply, i already tried this after that it worked.
Sign in to comment