Hello,
I recently made a change to a RadGrid by adding a Calculated column. My data source is an in-memory dataset. When I delete the final row in the grid and remove it from the dataset (in the code behind) I receive the following error:
Sys.WebForms.PageRequestManagerServerErrorException: Exception has been thrown by the target of an invocation.
I was able to get a little bit more information by adding a Rebind() to my grid in the deletion method. I received the following inner exception
{"This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row."}
I have further proven the calculated field is the cause, by simply removing the GridCalculatedColumn and re-running the code with no issues. The error return as soon as the calculated grid is added to the form.
Here's the markup:
And the code behind data source. The dataset is built and then stored to session. The data will be gathered later on submit.:
Finally the offending method that brakes the grid:
Any help on determining why the error occurs would be greatly appreciated.
Thank you,
I recently made a change to a RadGrid by adding a Calculated column. My data source is an in-memory dataset. When I delete the final row in the grid and remove it from the dataset (in the code behind) I receive the following error:
Sys.WebForms.PageRequestManagerServerErrorException: Exception has been thrown by the target of an invocation.
I was able to get a little bit more information by adding a Rebind() to my grid in the deletion method. I received the following inner exception
{"This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row."}
I have further proven the calculated field is the cause, by simply removing the GridCalculatedColumn and re-running the code with no issues. The error return as soon as the calculated grid is added to the form.
Here's the markup:
<
telerik:RadGrid
ID
=
"rdTicketGrid"
runat
=
"server"
Width
=
"70%"
AllowAutomaticUpdates
=
"false"
AllowAutomaticDeletes
=
"false"
AllowAutomaticInserts
=
"false"
AllowSorting
=
"false"
OnNeedDataSource
=
"rdTicketGrid_NeedDataSource"
AutoGenerateColumns
=
"false"
ShowFooter
=
"true"
OnInsertCommand
=
"rdTicketGrid_InsertCommand"
OnUpdateCommand
=
"rdTicketGrid_UpdateCommand"
OnItemCreated
=
"rdTicketGrid_ItemCreated"
OnDeleteCommand
=
"rdTicketGrid_DeleteCommand"
OnItemDataBound
=
"rdTicketGrid_ItemDataBound"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
MasterTableView
DataKeyNames
=
"TicketEntryID"
CommandItemDisplay
=
"Top"
InsertItemDisplay
=
"Top"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
></
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
DataField
=
"TicketEntryID"
UniqueName
=
"TicketEntryID"
Display
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"NumOfTickets"
HeaderText
=
"Number of Tickets"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"NumberTicketsInSet"
HeaderText
=
"Number of Tickets per Set"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"PriceOfTickets"
HeaderText
=
"Price of Tickets"
DataFormatString
=
"{0:C}"
></
telerik:GridBoundColumn
>
<
telerik:GridCalculatedColumn
HeaderText
=
"Total Amount"
UniqueName
=
"TotalSetAmount"
DataType
=
"System.Double"
DataFormatString
=
"{0:C}"
DataFields
=
"NumOfTickets, NumberTicketsInSet, PriceOfTickets"
Expression
=
"{0}/{1}*{2}"
FooterText
=
"Total: "
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
>
</
telerik:GridCalculatedColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this ticket entry?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
/>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
ButtonType
=
"ImageButton"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"rowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
<
telerik:RadInputManager
runat
=
"server"
ID
=
"rdInputMgr"
Enabled
=
"true"
>
<
telerik:NumericTextBoxSetting
BehaviorID
=
"TicketEntryIDTBSetting"
Type
=
"Number"
AllowRounding
=
"false"
DecimalDigits
=
"0"
></
telerik:NumericTextBoxSetting
>
<
telerik:NumericTextBoxSetting
BehaviorID
=
"NumTicketsTBSetting"
Type
=
"Number"
AllowRounding
=
"false"
DecimalDigits
=
"0"
></
telerik:NumericTextBoxSetting
>
<
telerik:NumericTextBoxSetting
BehaviorID
=
"PriceTicketsTBSetting"
Type
=
"Currency"
AllowRounding
=
"true"
DecimalDigits
=
"0"
></
telerik:NumericTextBoxSetting
>
<
telerik:NumericTextBoxSetting
BehaviorID
=
"NumberTicketsInSetTBSetting"
Type
=
"Number"
AllowRounding
=
"true"
DecimalDigits
=
"0"
></
telerik:NumericTextBoxSetting
>
</
telerik:RadInputManager
>
And the code behind data source. The dataset is built and then stored to session. The data will be gathered later on submit.:
DataSet ds =
new
DataSet();
DataTable dt =
new
DataTable();
dt.Columns.Add(
"TicketEntryID"
);
dt.Columns.Add(
"NumOfTickets"
,
typeof
(
int
));
dt.Columns.Add(
"NumberTicketsInSet"
,
typeof
(
int
));
dt.Columns.Add(
"PriceOfTickets"
,
typeof
(
double
));
ds.Tables.Add(dt);
Session[
"ticketGridSrc"
] = ds;.
Finally the offending method that brakes the grid:
protected
void
rdTicketGrid_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem editableItem = ((GridEditableItem)e.Item);
try
{
int
ticketEntryID =
int
.Parse(((GridDataItem)e.Item).GetDataKeyValue(
"TicketEntryID"
).ToString());
//Access the data stored in the session
DataSet currentDataSrc = ((DataSet)Session[
"ticketGridSrc"
]);
if
(currentDataSrc !=
null
)
{
//build the select string we need to get the data from the table to delete
String selectStmt =
string
.Format(
"TicketEntryID = '{0}'"
, ticketEntryID);
//Get the row we are deleting from the source.
DataRow[] updateRow = currentDataSrc.Tables[0].Select(selectStmt);
updateRow[0].Delete();
currentDataSrc.AcceptChanges();
}
Session[
"ticketGridSrc"
] = currentDataSrc;
}
catch
(Exception ex)
{
//TODO: Error Handling Here
}
}
Any help on determining why the error occurs would be greatly appreciated.
Thank you,