Obtaining values of selected values in Combo Box

I have a Telerik Combo Box that has a check box on each row. The user checks off each row he/she wishes to select. What I need to do is create a string of the selected values enclosed in single quotes, then seperated by commas. I'm getting a null reference to the RadComboBox and CheckBox. I'm passing the name of the ComboBox_Control and CheckBox_Control from another command line. Can someone assist?
------------------------------------------------------------
    Private Function get_checked_values(ByVal Combobox_Control As String, ByVal CheckBox_Control As String) As String

        'Holds the text of the checked items
        Dim oCheckString As String = ""
        Dim RadComboBox1 As New RadComboBox
        RadComboBox1 = CType(FindControl(Combobox_Control), RadComboBox)

        Dim checkedText As String = String.Empty
        For Each item As RadComboBoxItem In RadComboBox1.Items
            Dim chk As CheckBox = DirectCast(item.FindControl(CheckBox_Control), CheckBox)
            If chk.Checked Then
                If checkedText <> "" Then checkedText = checkedText & ","
                checkedText = checkedText & "'"
                checkedText = checkedText & item.Text
                checkedText = checkedText & "'"
            End If
        Next

        Return oCheckString

    End Function
OB1CanobieAsked:
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.

DeyhimCommented:
oCheckString is '' because no assign !!

return checkedText

but also it should += not only =


klakkasCommented:
From what I understand, your problem is that the line
       RadComboBox1 = CType(FindControl(Combobox_Control), RadComboBox)

does not return a valid control (returns nothing), so when you do
        For Each item As RadComboBoxItem In RadComboBox1.Items
you get a null reference exception.

If this is the case, then you are probably not passing the correct ID of the Combobox in the Combobox_Control parameter.

To verify the Combobox ID you can use Firebug (for Firefox), IE Dev Toolbar (for IE) or just get the page source and find the combo in there.
Arthur_WoodCommented:
try this change (based on Deyhim's answer, above)
    Private Function get_checked_values(ByVal Combobox_Control As String, ByVal CheckBox_Control As String) As String

        Dim RadComboBox1 As New RadComboBox
        RadComboBox1 = CType(FindControl(Combobox_Control), RadComboBox)

        Dim checkedText As String = String.Empty
        For Each item As RadComboBoxItem In RadComboBox1.Items
            Dim chk As CheckBox = DirectCast(item.FindControl(CheckBox_Control), CheckBox)
            If chk.Checked Then
                If checkedText <> String.Empty Then checkedText = checkedText & ","
                checkedText = checkedText & "'"
                checkedText = checkedText & item.Text
                checkedText = checkedText & "'"
            End If
        Next
        ' be sure to remove the final trailing ","
        Return checkedText   '<<<< note change here

    End Function  
 
AW

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
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
.NET Programming

From novice to tech pro — start learning today.