This is a migrated thread and some comments may be shown as answers.
Populate dropDownList in radGrid
4 Answers 102 Views
This is a migrated thread and some comments may be shown as answers.
DGraham
Top achievements
Rank 1
DGraham asked on 18 Jun 2009, 10:46 AM

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

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 18 Jun 2009, 12:57 PM
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.
0
DGraham
Top achievements
Rank 1
answered on 18 Jun 2009, 03:49 PM
Hi Shinu,

Thanks for your help, that's solved my problem...
0
Edgar
Top achievements
Rank 1
answered on 11 Nov 2015, 04:39 PM
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.
0
Eyup
Telerik team
answered on 16 Nov 2015, 08:47 AM
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
Tags
Grid
Asked by
DGraham
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
DGraham
Top achievements
Rank 1
Edgar
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or