954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting checkbox "Text" value in controls loop

Hey everyone,
I'm fairly new to ASP.Net and VB, but I have been learning pretty well. I have created a loop to go through one "View" section of a MultiView step form, and find which checkboxes have been checked. Depending on the boxes checked, I am trying to create new labels on a "Review" page that will display the "Text" attribute value of the checkbox that is being iterated through. This is my code below, for a few of the checkboxes as well as the loop. Currently it loops through correctly and displays the ID of the checkbox as that is what I have the loop doing, i'm just not sure how to access the text property.
Thanks in advance

<asp:View ID="View3" runat="server">
            <strong>6. Referral Source:</strong><asp:Panel ID="Panel7" runat="server">
                <asp:CheckBox ID="RefCurPat" runat="server" 
                    Text="Inquirer is former......" />
                
                <asp:CheckBox ID="RefFormPat" runat="server" 
                    Text="Inquirer heard about program......" />
                
                <asp:CheckBox ID="RefFriendFam" runat="server" Text="Friends / Family" />
                
                <asp:CheckBox ID="RefIntSearch" runat="server" AutoPostBack="True" 
                    Text="Internet Search: " />
                <asp:TextBox ID="RefIntSearchText" runat="server" Visible="False" 
                    Width="180px"></asp:TextBox>
For Each ctrl As Control In View4.Controls
            If TypeOf ctrl Is CheckBox Then
                If CType(ctrl, CheckBox).Checked = True Then
                    For i = 0 To ctrl.Controls.Count
                        Dim lbl As New Label
                        lbl.Text = ctrl.ID & "<br/>"
                        RefPanel.Controls.Add(lbl)
                    Next
                End If
            End If
        Next

any help is greatly appreciated.
Thanks again,
Nick G

nickg21
Newbie Poster
14 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

try below code

foreach (ViewItem lst in View4.Items)
{
if (lst.Selected)
{
}
}

crishlay
Junior Poster
132 posts since May 2010
Reputation Points: 10
Solved Threads: 16
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: