Solved

ASP.net hide RadioButtonList items

Posted on 2015-01-21
4
606 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:Murray Brown
[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:Murray Brown
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:Murray Brown
ID: 40570038
Thanks very much
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

624 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