This is a migrated thread and some comments may be shown as answers.

How to For Each in RadWebControl in master page

3 Answers 46 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Mohammed asked on 01 Oct 2013, 07:22 PM

How to For Each in RadWebControl with page or master page .

I need  For Each  control in page.RadWebControl. and Add ID and text in RadListBox1

Example :

RadListBox1.Items.Add(New RadListBoxItem(control .ID))
RadListBox1.Items.Add(New RadListBoxItem(control .text))




3 Answers, 1 is accepted

Sort by
0
Mohammed
Top achievements
Rank 1
answered on 02 Oct 2013, 10:15 AM
I am use this code. It works well, but there is a minor problem.

For Each c In ContentPlaceHolder1.Controls
 
            ' RadListBox1.Items.Add
            If c.ID IsNot Nothing Then
                RadListBox1.Items.Add(New RadListBoxItem(c.ID.ToString))
            End If
 
            'RadListBox2.Items.Add
            If TypeOf c Is RadAjaxPanel Then
                For Each childc In c.Controls
                    'If TypeOf childc Is RadTextBox Then
                    '    'allTextBoxValues &= CType(childc, TextBox).Text & ","
                    'End If
                    If childc.ID IsNot Nothing Then
                        RadListBox2.Items.Add(New RadListBoxItem(childc.ID.ToString))
                    End If
 'Here Not work, problem , NO Find Controls
                    If TypeOf childc Is UpdatePanel Then
                        Dim UpPL As UpdatePanel = CType(childc, UpdatePanel)
                        For Each child22 In UpPL.Controls
                            If child22.ID IsNot Nothing Then
                                RadListBox3.Items.Add(New RadListBoxItem(child22.ID.ToString))
                            End If
 
                            If TypeOf child22 Is Panel Then
                                Dim PL As Panel = CType(child22, Panel)
                                For Each child33 In PL.Controls
 
                                    If child33.ID IsNot Nothing Then
                                        RadListBox3.Items.Add(New RadListBoxItem(child33.ID.ToString))
                                    End If
                                Next
                            End If
                        Next
                    End If
 
                Next
            End If
Next
0
Dobromir
Telerik team
answered on 02 Oct 2013, 03:09 PM
Hi Mohammed,

You can use the following method to get all the RadControls registered on the page as a list:

Public Function FindRadControls(parent As Control) As List(Of RadWebControl)
    Dim result As New List(Of RadWebControl)()
    For Each c As Control In parent.Controls
 
        If TypeOf c Is Telerik.Web.UI.RadWebControl Then
            result.Add(TryCast(c, RadWebControl))
        End If
        If c.Controls.Count > 0 Then
            result.AddRange(FindRadControls(c))
        End If
    Next
    Return result
End Function


Regards,
Dobromir
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Mohammed
Top achievements
Rank 1
answered on 02 Oct 2013, 03:32 PM
Thank you, Mr.Dobromir 
I will inspect the code.
Tags
General Discussions
Asked by
Mohammed
Top achievements
Rank 1
Answers by
Mohammed
Top achievements
Rank 1
Dobromir
Telerik team
Share this question
or