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

    Hi,

     

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

     

    The custom form template is as follows:


    <FormTemplate> 
                  <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" /> 
    </FormTemplate> 

    In the code behind I have the following:

     

     

    Private

     

    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.DataBind()  
                contacts.DataTextField = "Description" 
                contacts.DataValueField = "Description" 
    End Sub

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

    Posted 18 Jun 2009 Link to this post

    Hello,

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

    VB:
     
    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 

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. 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...
  5. 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.
  6. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 16 Nov 2015 Link to this post

    Hi Edgar,

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

    https://msdn.microsoft.com/en-us/library/vstudio/ms178366%28v=vs.100%29.aspx

    In combination with the SelectedValue property, similar to this live sample:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

    And use the ExtractValues approach:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/manual-crud-operations/defaultcs.aspx

    Alternatively, you can access the value manually using FindControl method to get the combo in edit mode:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode


    Hope this helps.

    Regards,
    Eyup
    Telerik
    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
UI for ASP.NET Ajax is Ready for VS 2017