Template RadioButton

Discussion in 'ASP .Net Web Controls' started by Ben Schumacher, Jun 2, 2006.

  1. I have a template class that allows me to build a radio button into my
    gridview control. How do I make the radiobuttons that render in the
    gridview control so that only one can be cliked/checked at a time? The
    groupname property does nothing for me.

    Here is my template class ... FYI, it also handles the implementation of
    checkbox and image in the gridview columns. The code for the RadioButton is
    the last select case.

    Imports Microsoft.VisualBasic

    Public Class GridViewTemplate

    Implements ITemplate

    Dim templateType As DataControlRowType

    Dim controlid1 As String

    Dim controlenabled As Boolean

    Dim controltype As String



    Sub New(ByVal type As DataControlRowType, ByVal id1 As String, ByVal onoff
    As Boolean, ByVal typeofcontrol As String)

    templateType = type

    controlid1 = id1

    controlenabled = onoff

    controltype = typeofcontrol

    End Sub



    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
    Implements ITemplate.InstantiateIn



    Select Case templateType

    Case DataControlRowType.DataRow

    Select Case controltype

    Case "CheckBox"

    Dim oCheckBox As New CheckBox

    oCheckBox.ID = controlid1

    oCheckBox.Enabled = controlenabled

    container.Controls.Add(oCheckBox)

    oCheckBox = Nothing

    Case "Image"

    Dim oImage As New Image

    oImage.ID = controlid1

    oImage.Enabled = controlenabled

    container.Controls.Add(oImage)

    oImage = Nothing

    Case "Radio"

    Dim oRadioButton As New RadioButton

    oRadioButton.ID = controlid1

    oRadioButton.GroupName = "RadioList"

    oRadioButton.Enabled = controlenabled

    container.Controls.Add(oRadioButton)

    oRadioButton = Nothing

    End Select

    Case Else

    ' Unexpected Handler ...

    End Select



    End Sub



    End Class
    Ben Schumacher, Jun 2, 2006
    #1
    1. Advertising

  2. Ben Schumacher

    Guest

    http://www.codeproject.com/aspnet/How_group_RButtons.asp
    http://www.codeproject.com/aspnet/groupradiobuttons.asp

    You'll need to convert code above to a programmatic GridView with
    RadioButton grouping yourself.
    Good Luck.
    Andy

    Ben Schumacher wrote:
    > I have a template class that allows me to build a radio button into my
    > gridview control. How do I make the radiobuttons that render in the
    > gridview control so that only one can be cliked/checked at a time? The
    > groupname property does nothing for me.
    >
    > Here is my template class ... FYI, it also handles the implementation of
    > checkbox and image in the gridview columns. The code for the RadioButton is
    > the last select case.
    >
    > Imports Microsoft.VisualBasic
    >
    > Public Class GridViewTemplate
    >
    > Implements ITemplate
    >
    > Dim templateType As DataControlRowType
    >
    > Dim controlid1 As String
    >
    > Dim controlenabled As Boolean
    >
    > Dim controltype As String
    >
    >
    >
    > Sub New(ByVal type As DataControlRowType, ByVal id1 As String, ByVal onoff
    > As Boolean, ByVal typeofcontrol As String)
    >
    > templateType = type
    >
    > controlid1 = id1
    >
    > controlenabled = onoff
    >
    > controltype = typeofcontrol
    >
    > End Sub
    >
    >
    >
    > Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
    > Implements ITemplate.InstantiateIn
    >
    >
    >
    > Select Case templateType
    >
    > Case DataControlRowType.DataRow
    >
    > Select Case controltype
    >
    > Case "CheckBox"
    >
    > Dim oCheckBox As New CheckBox
    >
    > oCheckBox.ID = controlid1
    >
    > oCheckBox.Enabled = controlenabled
    >
    > container.Controls.Add(oCheckBox)
    >
    > oCheckBox = Nothing
    >
    > Case "Image"
    >
    > Dim oImage As New Image
    >
    > oImage.ID = controlid1
    >
    > oImage.Enabled = controlenabled
    >
    > container.Controls.Add(oImage)
    >
    > oImage = Nothing
    >
    > Case "Radio"
    >
    > Dim oRadioButton As New RadioButton
    >
    > oRadioButton.ID = controlid1
    >
    > oRadioButton.GroupName = "RadioList"
    >
    > oRadioButton.Enabled = controlenabled
    >
    > container.Controls.Add(oRadioButton)
    >
    > oRadioButton = Nothing
    >
    > End Select
    >
    > Case Else
    >
    > ' Unexpected Handler ...
    >
    > End Select
    >
    >
    >
    > End Sub
    >
    >
    >
    > End Class
    , Jun 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Theis
    Replies:
    2
    Views:
    467
    Chris Theis
    Jul 24, 2003
  2. tom_usenet
    Replies:
    0
    Views:
    533
    tom_usenet
    Jul 24, 2003
  3. =?Utf-8?B?QmFkaXM=?=

    Radiobutton item template

    =?Utf-8?B?QmFkaXM=?=, Dec 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    515
    Eliyahu Goldin
    Dec 5, 2006
  4. Anil

    Radiobutton Template column in Datagrid

    Anil, Sep 17, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    170
    Ravikanth[MVP]
    Sep 17, 2003
  5. gauty
    Replies:
    1
    Views:
    881
    Kashish Malhotra
    Apr 29, 2010
Loading...

Share This Page