TelerikDeveloper.com

TelerikDeveloper.com

sgray128 8/7/2012 11:25:26 AM

Telerik - Populate an ASPX GridDropDownList

The idea with populating a Telerik ASPX GridDropDownList is to do it in the ItemDataBound event. It's not too complicated, but it's a lot easier if you have a piece of sample code to copy in and start editing.

Edited 10/9/2012 With better code



ASPX

Notes:
I think we might need to use 'ListDataMember' here, not sure...

<telerik:GridDropDownColumn UniqueName="AssignedTo" ListTextField="UserName"
    ListValueField="UserID" HeaderText="Assigned To"
    DataField="AssignedTo" DropDownControlType="RadComboBox" AllowSorting="true">
</telerik:GridDropDownColumn>

 

Code Behind

Note:
Be sure to note the difference between the 'ComboBox' and 'ListBox' variations here.

Alternate way to populate the list box:

Dim ddList As DropDownList = Editor.DropDownListControl
ddList.Items.Clear()
ddList.DataSource = SPs.DD_SOPLineType_SEL().getTable
ddList.DataValueField = "LineType"
ddList.DataTextField = "LineType"
Editor.DataBind()

In this method, if you need data from the row, use this:

            Dim oRow As DataRowView = CType(e.Item.DataItem, DataRowView)             Dim strLineType As String = oRow("LineType")
            editor.SelectedValue = strLineType.Trim
    Private Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgsHandles RadGrid1.ItemDataBound
        If (TypeOf e.Item Is GridEditableItem AndAlso (e.Item.IsInEditMode)) Then
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim editMan As GridEditManager = editedItem.EditManager
 
            Dim editor As GridDropDownListColumnEditor = CType(editMan.GetColumnEditor("AssignedTo"), GridDropDownListColumnEditor)
            'in case you have RadComboBox editor for the GridDropDownColumn (this is the default editor),            
            'you will need to use ComboBoxControl below instead of DropDownListControl 
            'Then you can modify the list control as per your custom conventions
            editor.DataSource = SPs.DD_aspnet_UsersExt_SEL_byAccount(1).getTable
            editor.DataBind()
 
            editor.DropDownListControl.SelectedValue = "1"
            'And so on
        End If
 
    End Sub