Hi.
I got this error when i tried to edit the row in a hierarchical grid. I have one nested grid where i changed the UnitPrice value in ItemDataBound event. I need do divide the value to get the right currency. (If i do not, than i can do edit action in the nested grid without getting the error.) I have found in the forum other thread with the same error but it does not solve my case. The code i use is:
I got this error when i tried to edit the row in a hierarchical grid. I have one nested grid where i changed the UnitPrice value in ItemDataBound event. I need do divide the value to get the right currency. (If i do not, than i can do edit action in the nested grid without getting the error.) I have found in the forum other thread with the same error but it does not solve my case. The code i use is:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
LoadTransAndDetailValues(e);
}
}
private
void
LoadTransAndDetailValues(GridItemEventArgs e)
{
var item = e.Item
as
GridDataItem;
if
(e.Item.DataItem
is
Detail)
{
var detail = e.Item.DataItem
as
Detail;
double
? unitPrice = detail.UnitPrice;
item[
"UnitPrice"
].Text = (unitPrice.HasValue && unitPrice.Value != 0) ? (unitPrice.Value / 100.00).ToString() :
""
;
}
}
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
AllowSorting
=
"True"
GridLines
=
"None"
ShowGroupPanel
=
"True"
ShowStatusBar
=
"True"
Culture
=
"Norwegian, Bokmål (Norway)"
AutoGenerateColumns
=
"False"
Width
=
"620px"
onitemcommand
=
"RadGrid1_ItemCommand"
onitemdatabound
=
"RadGrid1_ItemDataBound"
AllowAutomaticUpdates
=
"True"
onneeddatasource
=
"RadGrid1_NeedDataSource"
onupdatecommand
=
"RadGrid1_UpdateCommand"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"TransId"
EditMode
=
"InPlace"
>
<
RowIndicatorColumn
><
HeaderStyle
Width
=
"20px"
></
HeaderStyle
></
RowIndicatorColumn
>
<
DetailTables
>
<
telerik:GridTableView
runat
=
"server"
AllowPaging
=
"False"
DataKeyNames
=
"DetailId"
AllowFilteringByColumn
=
"false"
EditMode
=
"InPlace"
DataSourceID
=
"DetailDataSource"
>
<
ParentTableRelation
><
telerik:GridRelationFields
DetailKeyField
=
"TransId"
MasterKeyField
=
"TransId"
/></
ParentTableRelation
>
<
CommandItemSettings
ExportToPdfText
=
"Export to Pdf"
></
CommandItemSettings
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"JourneyTime"
HeaderText
=
"Tur"
DataField
=
"JourneyTime"
ReadOnly
=
"true"
SortExpression
=
"JourneyTime"
AllowFiltering
=
"true"
ShowFilterIcon
=
"false"
AutoPostBackOnFilter
=
"true"
>
<
HeaderStyle
Width
=
"30px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"RouteName"
HeaderText
=
"Rute"
DataField
=
"RouteName"
ReadOnly
=
"true"
SortExpression
=
"RouteName"
AllowFiltering
=
"true"
ShowFilterIcon
=
"false"
AutoPostBackOnFilter
=
"true"
>
<
HeaderStyle
Width
=
"50px"
></
HeaderStyle
></
telerik:GridBoundColumn
>
<
telerik:GridNumericColumn
UniqueName
=
"TariffNr"
DataType
=
"System.Int32"
HeaderText
=
"Billettkode"
DataField
=
"TariffNr"
SortExpression
=
"TariffNr"
>
<
HeaderStyle
Width
=
"30px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
UniqueName
=
"DetailCount"
DataType
=
"System.Int32"
HeaderText
=
"Antall"
DataField
=
"DetailCount"
SortExpression
=
"DetailCount"
>
<
HeaderStyle
Width
=
"30px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
UniqueName
=
"UnitPrice"
HeaderText
=
"Pris"
DataField
=
"UnitPrice"
DataType
=
"System.Double"
SortExpression
=
"UnitPrice"
>
<
HeaderStyle
Width
=
"40px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridNumericColumn
>
<
telerik:GridEditCommandColumn
CancelText
=
"Avbryt"
EditText
=
"Endre"
InsertText
=
"Sett inn"
UpdateText
=
"Oppdater"
UniqueName
=
"EditColumn"
><
HeaderStyle
Width
=
"105px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridEditCommandColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
></
EditColumn
>
</
EditFormSettings
>
</
telerik:GridTableView
>
</
DetailTables
>
<
CommandItemSettings
ExportToPdfText
=
"Export to Pdf"
></
CommandItemSettings
>
<
ExpandCollapseColumn
Visible
=
"True"
></
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
DataField
=
"TransDate"
DataType
=
"System.DateTime"
HeaderText
=
"Dato"
ReadOnly
=
"True"
SortExpression
=
"TransDate"
UniqueName
=
"TransDate"
ShowFilterIcon
=
"false"
AutoPostBackOnFilter
=
"true"
>
<
HeaderStyle
Width
=
"140px"
></
HeaderStyle
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
DataField
=
"UserNr"
DataType
=
"System.Int32"
HeaderText
=
"Brukernr."
ReadOnly
=
"True"
SortExpression
=
"UserNr"
UniqueName
=
"UserNr"
ShowFilterIcon
=
"false"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"StartsWith"
>
<
HeaderStyle
Width
=
"100px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
DataField
=
"TicketNr"
DataType
=
"System.Int32"
HeaderText
=
"Billettnr."
ReadOnly
=
"True"
SortExpression
=
"TicketNr"
UniqueName
=
"TicketNr"
ShowFilterIcon
=
"false"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"StartsWith"
>
<
HeaderStyle
Width
=
"100px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
DataField
=
"AnnulComment"
HeaderText
=
"Annullerings kommentar"
SortExpression
=
"AnnulComment"
UniqueName
=
"AnnulComment"
ShowFilterIcon
=
"false"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"StartsWith"
>
<
HeaderStyle
Width
=
"200px"
></
HeaderStyle
></
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
CancelText
=
"Avbryt"
EditText
=
"Endre"
InsertText
=
"Sett inn"
UpdateText
=
"Oppdater"
UniqueName
=
"EditColumn"
>
<
HeaderStyle
Width
=
"105px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Annul"
Text
=
"Annuller"
UniqueName
=
"AnnulColumn"
><
HeaderStyle
Width
=
"50px"
></
HeaderStyle
></
telerik:GridButtonColumn
>
</
Columns
>
<
NoRecordsTemplate
><
div
>Det er ingen elementer å vise</
div
></
NoRecordsTemplate
>
</
MasterTableView
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
<
Resizing
AllowColumnResize
=
"true"
/>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
SortingSettings
EnableSkinSortStyles
=
"False"
SortedAscToolTip
=
"Sortert stigende"
SortedDescToolTip
=
"Sortet synkende"
SortToolTip
=
"Klikk her for å sortere"
/>
</
telerik:RadGrid
>
<
asp:LinqDataSource
ID
=
"DetailDataSource"
runat
=
"server"
ContextTypeName
=
"MtbsLinq.MtbsDataContext"
TableName
=
"Details"
Where
=
"TransId == @TransId"
EnableUpdate
=
"True"
>
<
WhereParameters
>
<
asp:ControlParameter
ControlID
=
"RadGrid1"
Name
=
"TransId"
PropertyName
=
"SelectedValue"
Type
=
"Int32"
DefaultValue
=
"0"
/>
</
WhereParameters
>
</
asp:LinqDataSource
>
</
asp:Content
>