How to dynamically reference comboBox?

3 posts, 1 answers
  1. Karl
    Karl avatar
    8 posts
    Member since:
    Apr 2011

    Posted 17 May 2011 Link to this post

    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. Answer
    Helen
    Admin
    Helen avatar
    1052 posts

    Posted 17 May 2011 Link to this post

    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.

  3. Karl
    Karl avatar
    8 posts
    Member since:
    Apr 2011

    Posted 17 May 2011 Link to this post

    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).
Back to Top