how to loop threw all combo boxes on a page

I have 13 combo boxes that the selected item is decided based on the result of a sql query.
I want to check all of the combo boxes for a value of "Not Done" and then set the background color to a different color.
I have named the combo boxes cmb1, cmb2, cmb2 and so on... I thought I could do something like this.. but I was wrong

For i As Integer = 1 To 13
            If cmb(i).....  then
                 do stuff

            End If

I think I might be way off here on how to pull this off.. any help would be great


        Next

Open in new window

David ModugnoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
You need to use the Controls collection to loop throw the controls on the page:
For Each cntrl As Control In Me.Controls
    If TypeOf cntrl Is ComboBox Then
        Dim cbobx As ComboBox = CType(cntrl, ComboBox)
        If cbobx.Text = "not selected" Then
            'Do Something
        End If
    End If
Next

Open in new window

1
it_saigeDeveloperCommented:
I would recommend one change to chaau's proposed solution:
For Each cntrl As Control In Me.Controls
    If TypeOf cntrl Is ComboBox Then
        Dim cbobx As ComboBox = CType(cntrl, ComboBox)
        If String.Equals(cbobx.Text, "not done", StringComparison.OrdinalIgnoreCase) Then
            'Do Something
        End If
    End If
Next

Open in new window

-saige-
1
David ModugnoAuthor Commented:
I gave it a go, but had no luck... I should have said that I am using telerik controls.. not sure if it makes a difference.. here is what I have ... thanks for the help

 For Each cntrl As Control In Me.Controls
            If TypeOf cntrl Is RadComboBox Then
                Dim cbobx As RadComboBox = CType(cntrl, RadComboBox)
                If cbobx.Text = "Not Done" Then
                    cbobx.BackColor = Color.Orange
                End If
            End If
        Next

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

MlandaTCommented:
It should not matter that you are using Telerik. Your code looks correct (I also use Telerik a lot). The concept is the same. You need to tell us more about what exactly has not worked here.

If you put a breakpoint on line 3 on your last snippet, do you reach that breakpoint? In other words, are you finding any of the RadComboBoxes?  
In which method are you doing this... Hopefully not Page_Init? Coz maybe your changes get overwritten when ViewState is restore AFTER the Page_Init call
You are looping through Me.Controls... Is that the parent container closest to the radcomboboxes? You might be looping through the wrong controls collection...
What sort of controls are you finding in Me.Controls? Should you recursively loop through their own controls collections as well?
0
David ModugnoAuthor Commented:
Break point... It does not reach it

right now I have the code behind a button (for testing)..
after the page loads.. all combo boxes are filled and the correct value is selected I click the button expecting it to change the background color

you will have to forgive me on the next two ?'s.. I'm not a very experienced programmer and am not exactly sure what you are asking

its a single asp page with all the controls on it and vb.net code behind..
0
MlandaTCommented:
Perhaps you might have to show us some more of the code
0
David ModugnoAuthor Commented:
I think I understand what you are saying, but don't know what to do about it.  the combo boxes are inside of a container

Here is some of the code

<telerik:RadSplitter ID="RadSplitter3" runat="server" SplitBarsSize="" LiveResize="True" Width="1200px" Height="600px">
                       <telerik:RadPane ID="RadPane5" Runat="server" Height="600px" Width="700px">
                            <br /><br />
                            <table class="nav-justified">
                                <tr>
                                    <td class="auto-style111">&nbsp;</td>
                                    <td class="auto-style112">STATUS</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="auto-style111">Survey Complete</td>
                                    <td class="auto-style112">
                                        <telerik:RadComboBox ID="cmb1" Runat="server">
                                            <Items>
                                                <telerik:RadComboBoxItem runat="server" Text="Done" Value="Done" />
                                                <telerik:RadComboBoxItem runat="server" Text="Not Done" Value="Not Done" />
                                                <telerik:RadComboBoxItem runat="server" Text="N/A" Value="N/A" />
                                            </Items>
                                        </telerik:RadComboBox>
                                    </td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>

Open in new window

0
MlandaTCommented:
Try this. Note that I have changed the For loop. It now loops through RadPane5.Controls  
 For Each cntrl As Control In RadPane5.Controls
            If TypeOf cntrl Is RadComboBox Then
                Dim cbobx As RadComboBox = CType(cntrl, RadComboBox)
                If cbobx.Text = "Not Done" Then
                    cbobx.BackColor = Color.Orange
                End If
            End If
        Next

Open in new window

Now, to understand the server side code? You say breakpoint is not being hit... At what point are you long through the controls? Is it on a button click? Is that button click event being hit at all?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David ModugnoAuthor Commented:
Thank you for the help and the lesson.. that works perfect
2
MlandaTCommented:
Glad to help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.