Solved

ASP.net hide RadioButtonList items

Posted on 2015-01-21
4
504 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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