views:

24

answers:

0

I have created a custom RadioButton control, because I needed to set additional values in to it. But regardless of whether the UI shows the control as checked or not the control does not have a True property for checked.

The outer repeater iterates through Qualifications, which contain a List of Subjects. The subjects are iterated through in the nested repeater. The idea is that the user will select 1 subject. I need to save the subject they've selected and the qualification it belongs to back to an object. My RadioButtonWithCode adds 2 Properties (QualCode and IDCode). I can get into the properties when the form is submitted and am checking to see which RadioButtonWithCode.Checked = True...

<asp:Repeater ID="rpQuals" runat="server">
    <HeaderTemplate><dl></HeaderTemplate>
    <ItemTemplate>
        <dt class="pseudoLink" onclick="JavaScript: toggleEvent('<%#Eval("Code") %>');"><%#Eval("Name")%></dt>
        <dd id='<%#Eval("Code") %>' class="EventDetails hide" style="display: none;">
            <asp:Repeater ID="rpSubjects" runat="server" EnableViewState="false" DataSource='<%#Eval("Subjects") %>'>
                <HeaderTemplate><ul></HeaderTemplate>
                <FooterTemplate></ul></FooterTemplate>
                <ItemTemplate><li><ifs:RadioButtonWithCode ID="rbSubjects" runat="server" 
                                       GroupName="SubjectList"
                                       EnableViewState="true"
                                       QualCode='<%#DataBinder.Eval(container, "Parent.Parent.DataItem.Code") %>'
                                       Text='<%#Eval("Name") %>' 
                                       OnCheckedChanged="OnCheckedItem"
                                       IDCode='<%#Eval("Code") %>' /></li>
                </ItemTemplate>
            </asp:Repeater>
        </dd>
    </ItemTemplate>
    <FooterTemplate></dl></FooterTemplate>
</asp:Repeater>

and the RadioButtonWithCode class:

Imports System.ComponentModel

Namespace ifs.Web.Controls

Public Class RadioButtonWithCode
    Inherits RadioButton

Region "Fields"

    Private _iDCode As String

    Private _qualCode As String

End Region

Region "Properties"

    <Bindable(True), _
    Category("Properties"), _
    Description("Gives an extra property for setting ID/Code"), _
    DefaultValue("")> _
    Public Property IDCode() As String
        Get
            Return _iDCode
        End Get
        Set(ByVal Value As String)
            _iDCode = Value
        End Set
    End Property

    <Bindable(True), _
    Category("Properties"), _
    Description("Qualification Code the subject belongs to"), _
    DefaultValue("")> _
    Public Property QualCode() As String
        Get
            Return _qualCode
        End Get
        Set(ByVal Value As String)
            _qualCode = Value
        End Set
    End Property

End Region

Region "Protected Methods"

    Protected Overrides Sub RenderContents(ByVal writer As System.Web.UI.HtmlTextWriter)
        Dim sb As New StringBuilder()
        sb = sb.AppendFormat(String.Format("<input type='radio' name='{1}' id='{2}' value='{1}' IDCode='{2}' QualCode='{3}' />", ID, GroupName, IDCode, QualCode))
        sb = sb.AppendFormat(String.Format("<label for='{0}'>{1}</label>", IDCode, Text))
        writer.Write(sb.ToString())

    End Sub

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        RenderContents(writer)
    End Sub

    Protected Overrides Sub OnCheckedChanged(ByVal e As System.EventArgs)
        MyBase.OnCheckedChanged(e)
    End Sub

End Region

End Class

End Namespace