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?
Any ideas?
Private Sub printersGrid_ItemCreated(ByVal sender As Object, ByVal 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 Object, ByVal 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 Object, ByVal 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 |