Solved

ASP.net hide RadioButtonList items

Posted on 2015-01-21
4
552 Views
Last Modified: 2015-01-25
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
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 40563386
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")
0
 

Author Comment

by:murbro
ID: 40563629
Hi thanks Jesus. Where would I put this code? Thanks. Murray
0
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 500 total points
ID: 40564504
In your RowDatabound event you can do something like this

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.Remove(rdb.Items.FindByValue(rdb.items(2).value))
                     rdb.Items.Remove(rdb.Items.FindByValue(rdb.items(3).value))
                     rdb.Items.Remove(rdb.Items.FindByValue(rdb.items(4).value))
                 ElseIf oNumberAnswers = "3" Then
                     rdb.Items.Remove(rdb.Items.FindByValue(rdb.items(3).value))
                     rdb.Items.Remove(rdb.Items.FindByValue(rdb.items(4).value))
                 ElseIf oNumberAnswers = "4" Then
                     rdb.Items.Remove(rdb.Items.FindByValue(rdb.items(4).value))
                 End If
             End If
         Catch ex As Exception
             Response.Write(ex.Message)
         End Try
     End Sub 

Open in new window

               
        if you use  RadioButtonList1.Items(Element_Index).Attributes.Add("style", "visibility:hidden") then you will have an space between each element that will be hidden
0
 

Author Closing Comment

by:murbro
ID: 40570038
Thanks very much
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question