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

How to dynamically reference comboBox?

2 Answers 59 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 17 May 2011, 01:42 PM
I have a project that previously used asp dropdown lists.  I am switching these over to telerik controls for increased functionality.  However, I need to be able to dynamically reference and populate the controls in the page load event.  Here is how I used to accomplish this:

Dim dropDown As New DropDownList
dropDown = CType(Me.Master.FindControl("id_" & dynamic_code), DropDownList)
 
With dropDown
    .Enabled = True
    .DataSource = SqlDataReader
    .DataValueField = "code"
    .DataTextField = "desc"
    .DataBind()
End With


How do I replicate this behavior with a telerik control?  I've tried something like this:

Dim dropDown As RadComboBoxItem
Dim instance As RadComboBoxItem
 
dropDown = instance.FindControl("id_" & dynamic_code)
 
With dropDown
    .Enabled = True
    .DataSource = SqlDataReader
    .DataValueField = "code"
    .DataTextField = "desc"
    .DataBind()
End With

But the properties I'm trying to set are invalid and do not exist.  Suggestions or help appreciated.

2 Answers, 1 is accepted

Sort by
0
Accepted
Helen
Telerik team
answered on 17 May 2011, 02:42 PM
Hi Karl,

Could you please try the following:

Dim dropDown As RadComboBox
dropDown = CType(Me.Master.FindControl("id_" & dynamic_code), RadComboBox)
 
With dropDown
    .Enabled = True
    .DataSource = SqlDataReader
    .DataValueField = "code"
    .DataTextField = "desc"
    .DataBind()
End With


Greetings,
Helen
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Karl
Top achievements
Rank 1
answered on 17 May 2011, 02:52 PM
Looks like I was making it more complicated than it needed to be.  Your solution worked perfectly, thanks.

For anyone interested, to use FindControl with a master page in this manner, I had to append "content$" to the ID of the control I was trying to find (I'm not sure if "content" must match the ID of your content place holder, but it does in my case).
Tags
ComboBox
Asked by
Karl
Top achievements
Rank 1
Answers by
Helen
Telerik team
Karl
Top achievements
Rank 1
Share this question
or