This is a migrated thread and some comments may be shown as answers.
Dynamic controls on RadGrid EditColumn
0 Answers 23 Views
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 02 Jul 2012, 04:22 PM
I am dynamically generating a list of columns for a radgrid and everything there is fine the issue that occurs when I'm trying to convert a GridBoundcColumn to a GridDropDownListColumnEditor on the CreateColumnEditor

I was wondering if it was possible to add to add a drop down list, combo box or even a lookup button to the edit template on the radgrid
*Note the datatable is just for testing the columns are coming from a database

Public Property DT As DataTable
     Get
         Return ViewState("DT")
     End Get
     Set(ByVal value As DataTable)
         ViewState("DT") = value
     End Set
 End Property
 
 
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     If Not Page.IsPostBack Then
         AddEditColumn()
         DT = GetData()
     End If
 End Sub
 
 
 Private Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
     Me.RadGrid1.DataSource = DT
 End Sub
 
 Sub AddEditColumn()
     If Not RadGrid1.Columns.Contains("GridEditCommandColumn") Then
         Dim EditCol As New GridEditCommandColumn
         RadGrid1.Columns.Add(EditCol)
     End If
 End Sub
 
 Private Sub RadGrid1_CreateColumnEditor(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCreateColumnEditorEventArgs) Handles RadGrid1.CreateColumnEditor
     If (TypeOf e.Column Is GridBoundColumn) Then
         If (CType(e.Column, GridBoundColumn).DataField = "Customer") Then
             e.ColumnEditor = New GridTextBoxColumnEditor
             'e.ColumnEditor.ContainerControl.Controls
         ElseIf (CType(e.Column, GridBoundColumn).DataField = "CustomerType") Then
             'e.ColumnEditor = New GridDropDownListColumnEditor
         End If
     End If
 End Sub
 
 Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
     If (TypeOf e.Item Is GridDataItem) Then
         Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
 
     ElseIf (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
         Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
 
     End If
 End Sub
 
 Private Function GetData()
     Dim datatable As New DataTable
     datatable.Columns.Add("Customer", GetType(String))
 
     datatable.Columns.Add("CustomerType", GetType(String))
     '********************************************************
     'CustomerType is the Column that needs to be a drop down.     
    
'********************************************************
 
     datatable.Columns.Add("QtyOrd", GetType(Integer))
     datatable.Columns.Add("Date1", GetType(Date))
     datatable.Columns.Add("Date2", GetType(Date))
     datatable.Columns.Add("OnTime", GetType(Boolean))
 
     datatable.Rows.Add({("A&A Beef"), ("WHOL"), 1, DateTime.Now, DateTime.Now, False})
     datatable.Rows.Add({("Vegmart"), ("RET"), 8, DateTime.Now, DateTime.Now, False})
 
     Return datatable
 End Function

No answers yet. Maybe you can help?

Asked by
Andy
Top achievements
Rank 1
Share this question
or