Home All Groups Group Topic Archive Search About
Author
2 Jun 2006 4:31 PM
Ben Schumacher
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

Author
2 Jun 2006 10:41 PM
CaffieneRush@gmail.com
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:
Show quoteHide quote
> 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