Solved

ASP.net hide RadioButtonList items

Posted on 2015-01-21
4
405 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
Comment Utility
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
Comment Utility
Hi thanks Jesus. Where would I put this code? Thanks. Murray
0
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 500 total points
Comment Utility
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
Comment Utility
Thanks very much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now