Populate dropDownList in radGrid

5 posts, 1 answers
  1. DGraham
    DGraham avatar
    31 posts
    Member since:
    Sep 2008

    Posted 18 Jun 2009 Link to this post



    How can I populate a ‘dropDownList’ inside a radGrid from the code behind?


    The custom form template is as follows:

                  <asp:Label ID = "lblContact" runat ="server" text = "Contact"></asp:Label> 
                  <asp:DropDownList ID="ddlContacts" runat ="server" DataValueField ="Description" DataTextField ="description"/> <br/><br /> 
                  <asp:Button ID="btnSubmit" runat ="server" Text ="Submit" /> 
                  <asp:Button ID="btnCancel" runat ="server" Text ="Cancel" /> 

    In the code behind I have the following:





    Sub RadGridService_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGridServices.NeedDataSource





                Dim objContacts As Array  
                'Gets data from web service  
                objContacts = objReceptionBureauService.getAllContactsForEmployee("EmployeeID")  
                Dim contacts As DropDownList = TryCast(FindControl("ddlContacts"), DropDownList)  
                contacts.DataSource = objContacts  
                contacts.DataTextField = "Description" 
                contacts.DataValueField = "Description" 
    End Sub

  2. Answer
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Jun 2009 Link to this post


    Try the following code snippet in order to populate the DropDownList which is placed in FormTemplate.

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) 
        If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then 
            Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem) 
            Dim dropdown As DropDownList = DirectCast(item.FindControl("ddlContacts"), DropDownList) 
            'Populate the dropdownlist 
        End If 
    End Sub 

  3. DGraham
    DGraham avatar
    31 posts
    Member since:
    Sep 2008

    Posted 18 Jun 2009 Link to this post

    Hi Shinu,

    Thanks for your help, that's solved my problem...
  4. Edgar
    Edgar avatar
    4 posts
    Member since:
    Oct 2014

    Posted 11 Nov 2015 in reply to Shinu Link to this post

    Hi, I am using this approach but when I use ItemCommand "Update" the dropdown is empty and I can't find the edited selected value.
  5. Eyup
    Eyup avatar
    3990 posts

    Posted 16 Nov 2015 Link to this post

    Hi Edgar,

    You can use the the Bind or Eval expression to achieve this requirement:


    In combination with the SelectedValue property, similar to this live sample:

    And use the ExtractValues approach:

    Alternatively, you can access the value manually using FindControl method to get the combo in edit mode:

    Hope this helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top