This is a migrated thread and some comments may be shown as answers.

How Do I Reference EditForm UserControl when inserting a new record

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris Kraft
Top achievements
Rank 1
Chris Kraft asked on 20 May 2010, 01:37 AM
I am trying to use an existing UserControl(PrinterSettingsControl) as the PopUp EditForm for a RadGrid which is bound to a business object ( IList(Of ClientSidePrinterProperties)  ) and I need to set the value of a couple of properties on the user control to make it operate properly. Below is the code I have working on for editing an existing entry, but I can't figure out how to accomplish the same functionality for adding a new record, specifically finding the UserControl like the e.Item.FindControl() shown below. I have tried manipulating the ItemCreated, ItemDataBound and ItemCommand event handlers but just can't seem to find the control.

Any ideas?

 

 

    Private Sub printersGrid_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles printersGrid.ItemCreated  
 
        Debug.WriteLine("In ItemCreated")  
        Debug.Indent()  
        Debug.WriteLine("e.Item.ToString = " & e.Item.ToString)  
 
 
        Dim printerSettingsControl As PrinterSettingsControl  
 
        If TypeOf e.Item Is GridEditFormItem And e.Item.IsInEditMode Then 
 
            Dim clientSettings As ClientSidePrinterProperties  
 
            printerSettingsControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), PrinterSettingsControl)  
 
            If e.Item.OwnerTableView.IsItemInserted Then 
                Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)  
            Else 
 
                clientSettings = DirectCast(e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Settings"), ClientSidePrinterProperties)  
 
                printerSettingsControl.Options = printerSettingsControl.Option.ShowUpdateCancelButtons  
                printerSettingsControl.IsRaw = ViewState("IsRaw")  
                printerSettingsControl.Locked = ViewState("locked")  
                printerSettingsControl.PopulateControls(clientSettings)  
 
            End If 
 
        End If 
 
        'If TypeOf e.Item Is GridEditFormItem Then  
 
        '    Dim clientSettings As ClientSidePrinterProperties  
 
        '    If e.Item.IsInEditMode Then  
 
        '        clientSettings = DirectCast(e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Settings"), ClientSidePrinterProperties)  
 
        '        printerSettingsControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), PrinterSettingsControl)  
 
        '        printerSettingsControl.Options = printerSettingsControl.Option.ShowUpdateCancelButtons  
        '        printerSettingsControl.IsRaw = ViewState("IsRaw")  
        '        printerSettingsControl.Locked = ViewState("locked")  
        '        printerSettingsControl.PopulateControls(clientSettings)  
 
        '    ElseIf e.Item.OwnerTableView.IsItemInserted Then  
 
        '        Debug.WriteLine("IsItemInserted")  
 
        '        printerSettingsControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), PrinterSettingsControl)  
 
        '        If printerSettingsControl IsNot Nothing Then  
 
        '            Debug.WriteLine(printerSettingsControl.ToString)  
 
        '        End If  
 
        '    End If  
 
        'End If  
 
        Debug.Unindent()  
 
    End Sub 'RadGrid1_ItemCreated  
 
 
    Private Sub printersGrid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles printersGrid.ItemDataBound  
 
        Debug.WriteLine("In ItemDataBound")  
        Debug.Indent()  
 
        Debug.WriteLine("e.Item.ToString = " & e.Item.ToString)  
 
        If TypeOf e.Item Is GridEditFormItem And e.Item.IsInEditMode Then 
 
            If e.Item.OwnerTableView.IsItemInserted Then 
                Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)  
            Else 
                Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)  
            End If 
 
        End If 
 
        Debug.Unindent()  
 
    End Sub 'RadGrid1_ItemDataBound  
 
 
    Private Sub printersGrid_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles printersGrid.ItemCommand  
 
        Debug.WriteLine("In ItemCommand")  
        Debug.Indent()  
        Debug.WriteLine("e.CommandName.ToString = " & e.CommandName.ToString)  
 
        If e.CommandName = RadGrid.InitInsertCommandName Then 
            e.Canceled = True 
 
            Dim newValues As New System.Collections.Specialized.ListDictionary  
 
            newValues("Settings") = ClientSidePrinterProperties.CreateDefault  
 
            e.Item.OwnerTableView.InsertItem(newValues)  
 
        End If 
 
        Debug.Unindent()  
 
    End Sub 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 25 May 2010, 08:53 AM
Hello Chris,

Try checking if your item is GridEditFormInsertItem and if it is in edit mode:

Private Sub printersGrid_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles printersGrid.ItemCreated 
    '...
 
    If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.IsInEditMode Then 
        '...
 
        Debug.WriteLine("IsItemInserted"
            printerSettingsControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), PrinterSettingsControl) 
            If printerSettingsControl IsNot Nothing Then 
                Debug.WriteLine(printerSettingsControl.ToString) 
        End If 
    End If 
    Debug.Unindent() 
End Sub 'RadGrid1_ItemCreated


Kind regards,
Veli
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Chris Kraft
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or