I'm trying to load the combobox that is inside the radgrid using the RadGrid1_ItemCommand, using the command to insert a new line into the radgrid that is empty, but the following error is displayed: Can not convert an object of type 'Telerik.Web.UI .GridCommandItem 'in type' Telerik.Web.UI.GridEditableItem. Here's a part of the code:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
ShowStatusBar
=
"true"
AllowSorting
=
"true"
SortingSettings-EnableSkinSortStyles
=
"false"
AllowAutomaticDeletes
=
"true"
AllowAutomaticInserts
=
"true"
AllowAutomaticUpdates
=
"True"
AllowMultiRowSelection
=
"true"
HorizontalAlign
=
"Center"
PageSize
=
"10"
EnableViewState
=
"false"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"NRO_ITEM"
>
<
NoRecordsTemplate
>
<
div
> Sem itens </
div
>
</
NoRecordsTemplate
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"TRB_LOTE_NRO"
DataField
=
"TRB_LOTE_NRO"
HeaderText
=
"TRB_LOTE_NRO"
/>
<
telerik:GridBoundColumn
UniqueName
=
"QUANTIDADE"
DataField
=
"QUANTIDADE"
DataType
=
"System.Int32"
HeaderText
=
"QUANTIDADE"
/>
<
telerik:GridBoundColumn
UniqueName
=
"TIPO"
DataField
=
"TIPO"
HeaderText
=
"TIPO"
/>
<
telerik:GridBoundColumn
UniqueName
=
"DESCRICAO"
DataField
=
"DESCRICAO"
HeaderText
=
"DESCRICAO"
/>
<
telerik:GridBoundColumn
UniqueName
=
"ID_RT"
DataField
=
"ID_RT"
HeaderText
=
"RT"
/>
<
telerik:GridBoundColumn
UniqueName
=
"ID_NRO_GMM"
DataField
=
"ID_NRO_GMM"
HeaderText
=
"ID_NRO_GMM"
DataType
=
"System.Int32"
Visible
=
"false"
/>
<
telerik:GridBoundColumn
UniqueName
=
"NRO_ITEM"
DataField
=
"NRO_ITEM"
HeaderText
=
"NRO_ITEM"
DataType
=
"System.Int32"
Visible
=
"false"
/>
<
telerik:GridEditCommandColumn
HeaderStyle-Width
=
"100px"
HeaderText
=
"Edita"
/>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
UniqueName
=
"DeleteColumn"
HeaderStyle-Width
=
"100px"
Text
=
"Delete"
/>
</
Columns
>
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
<
div
style
=
"width: 300px"
>
<
div
style
=
"margin:5px;"
>
<
asp:Label
ID
=
"TRB_LOTE_NROLbl"
runat
=
"server"
Text
=
"Trb_Lote_Nro:"
/> <
telerik:RadComboBox
ID
=
"TRB_LOTE_NROCmbGrid"
runat
=
"server"
Text='<%# Bind("TRB_LOTE_NRO") %>' />
</
div
>
<
div
style
=
"margin:5px;"
>
<
asp:Label
ID
=
"QUANTIDADELbl"
runat
=
"server"
Text
=
"Quantidade:"
meta:resourceKey
=
"QUANTIDADELbl"
/> <
asp:TextBox
ID
=
"QUANTIDADETxtGrid"
runat
=
"server"
Text='<%# Bind("QUANTIDADE") %>'/>
</
div
>
<
div
style
=
"margin:5px;"
>
<
asp:Label
ID
=
"TIPOLbl"
runat
=
"server"
Text
=
"Tipo:"
/> <
telerik:RadComboBox
ID
=
"TIPOCmbGrid"
runat
=
"server"
/>
</
div
>
<
div
style
=
"margin:5px;"
>
<
asp:Label
ID
=
"DESCRICAOLbl"
runat
=
"server"
Text
=
"Descrição:"
/> <
asp:TextBox
ID
=
"DESCRICAOTxtGrid"
runat
=
"server"
Text='<%# Bind("DESCRICAO") %>'/>
</
div
>
<
div
style
=
"margin:5px;"
>
<
asp:Label
ID
=
"ID_RT"
runat
=
"server"
Text
=
"RT:"
/> <
telerik:RadComboBox
ID
=
"ID_RTCmbGrid"
runat
=
"server"
Text='<%# Bind("ID_RT") %>' />
</
div
>
<
div
style
=
"margin:10px;text-align:right;"
>
<
telerik:RadButton
ID
=
"btnUpdate"
Text='<%# IIf((TypeOf (Container) Is GridEditFormInsertItem), AddJS, UpdateJS) %>' runat="server" CommandName='<%# IIf((TypeOf (Container) Is GridEditFormInsertItem), "PerformInsert", "Update")%>'/>
<
telerik:RadButton
ID
=
"btnCancel"
runat
=
"server"
CausesValidation
=
"False"
CommandName
=
"Cancel"
Text
=
"Cancelar"
/>
</
div
>
</
div
>
</
FormTemplate
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
<
Scrolling
AllowScroll
=
"True"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
Private
Sub
RadGrid1_ItemCommand(sender
As
Object
, e
As
GridCommandEventArgs)
Handles
RadGrid1.ItemCommand
If
e.CommandName = RadGrid.InitInsertCommandName
Then
'"Add new" button clicked
e.Canceled =
True
Dim
newValues
As
New
System.Collections.Specialized.ListDictionary()
newValues(
"ID_RT"
) =
""
newValues(
"DESCRICAO"
) =
""
newValues(
"QUANTIDADE"
) =
""
newValues(
"TRB_LOTE_NRO"
) =
""
newValues(
"NRO_ITEM"
) =
""
e.Item.OwnerTableView.InsertItemPageIndexAction = GridInsertItemPageIndexAction.ShowItemOnCurrentPage
e.Item.OwnerTableView.InsertItem(newValues)
'If Not (TypeOf e.Item Is IGridInsertItem) Then
Dim
editform
As
GridEditFormItem =
DirectCast
(
DirectCast
(e.Item, Telerik.Web.UI.GridDataItem).EditFormItem, GridEditFormItem)
Dim
comboTrbLote
As
RadComboBox =
DirectCast
(editform.FindControl(
"TRB_LOTE_NROCmbGrid"
), RadComboBox)
Dim
comboTipo
As
RadComboBox =
DirectCast
(editform.FindControl(
"TIPOCmbGrid"
), RadComboBox)
Dim
comboRT
As
RadComboBox =
DirectCast
(editform.FindControl(
"ID_RTCmbGrid"
), RadComboBox)
Expressao =
"SELECT DISTINCT ID_EMP_ESTAB FROM EMPRESAS WHERE ESTAB= '"
& DepartamentoCmb.Text &
"'"
TabelaAdapter =
New
OleDbDataAdapter(Expressao, conexao)
'preenche o datatable
Tabela =
New
DataTable
TabelaAdapter.Fill(Tabela)
id_estab = Tabela.Rows(0).Item(0).ToString
Expressao =
"SELECT TRABALHOS.ID_NRO_TRAB, TRABALHOS.ID_NRO_MAQ, TRABALHOS.VERSAO FROM TRABALHOS, CONTRATOS "
&
"WHERE TRABALHOS.ID_CONTRATO = CONTRATOS.ID_CONTRATO AND CONTRATOS.ATIVO=TRUE AND CONTRATOS.ID_EMP_ESTAB = "
& id_estab &
" ORDER BY TRABALHOS.ID_NRO_TRAB, TRABALHOS.ID_NRO_MAQ, TRABALHOS.VERSAO ASC"
TabelaAdapter =
New
OleDbDataAdapter(Expressao, conexao)
'preenche o datatable
Tabela =
New
DataTable
TabelaAdapter.Fill(Tabela)
For
i = 0
To
Tabela.Rows.Count - 1
comboTrbLote.Items.Add(Tabela.Rows(i).Item(0).ToString &
"."
& Tabela.Rows(i).Item(1).ToString &
"-"
& Tabela.Rows(i).Item(2).ToString)
Next
Expressao =
"SELECT MATERIAL FROM TIPO_MATERIAL_GMM"
TabelaAdapter =
New
OleDbDataAdapter(Expressao, conexao)
Tabela =
New
DataTable
TabelaAdapter.Fill(Tabela)
For
i = 0
To
Tabela.Rows.Count - 1
comboTipo.Items.Add(Tabela.Rows(i).Item(0).ToString)
Next
Expressao =
"SELECT CONTRATOS.ID_CONTRATO, CONTRATOS.ID_EMP_ESTAB, ID_RT "
&
"FROM EMPRESAS INNER JOIN (CONTRATOS INNER JOIN RTS ON CONTRATOS.ID_CONTRATO = RTS.ID_CONTRATO) "
&
"ON EMPRESAS.ID_EMP_ESTAB = CONTRATOS.ID_EMP_ESTAB WHERE CONTRATOS.ATIVO=TRUE AND EMPRESAS.ID_EMP_ESTAB = "
& id_estab &
" ORDER BY ID_RT"
TabelaAdapter =
New
OleDbDataAdapter(Expressao, conexao)
'preenche o datatable
Tabela =
New
DataTable
TabelaAdapter.Fill(Tabela)
For
i = 0
To
Tabela.Rows.Count - 1
comboRT.Items.Add(Tabela.Rows(i).Item(2).ToString)
Next
ElseIf
(e.CommandName = RadGrid.RebindGridCommandName
AndAlso
e.Item.OwnerTableView.IsItemInserted)
Then
e.Canceled =
True
Else
Dim
editColumn
As
GridEditCommandColumn =
CType
(RadGrid1.MasterTableView.GetColumn(
"EditCommandColumn"
), GridEditCommandColumn)
If
Not
editColumn.Visible
Then
editColumn.Visible =
True
End
If
End
If
End
Sub
greetings