Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net hide RadioButtonList items

Hi

I am using the following code to disable RadioButtonList items. Is it possible to hide them instead?


  Private Sub GridView3_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound
        Try
            ' Required to ignore the header and footer rows
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim oNumberAnswers As String = CStr(e.Row.Cells(4).Text)

                Dim rdb As RadioButtonList = DirectCast(e.Row.FindControl("RadioButtonList1"), RadioButtonList)

                If oNumberAnswers = "2" Then
                    rdb.Items(2).Enabled = False
                    rdb.Items(3).Enabled = False
                    rdb.Items(4).Enabled = False
                ElseIf oNumberAnswers = "3" Then
                    rdb.Items(3).Enabled = False
                    rdb.Items(4).Enabled = False
                ElseIf oNumberAnswers = "4" Then
                    rdb.Items(4).Enabled = False

                End If
            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub
Avatar of Jesus Rodriguez
Jesus Rodriguez
Flag of United States of America image

Under the hood, you can access the attributes of the item and assign it a CSS style.
So you should be able to then programmatically assign it by specifying:

RadioButtonList.Items(1).CssClass.Add("visibility", "hidden")
Avatar of Murray Brown

ASKER

Hi thanks Jesus. Where would I put this code? Thanks. Murray
ASKER CERTIFIED SOLUTION
Avatar of Jesus Rodriguez
Jesus Rodriguez
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much