I'm getting an exception System.ArgumentOutOfRangeException thrown in the ItemDataBound callback of a RadComboBox that is in a GridDropDownColumn; breaking on editableItem.GetDataKeyValue() after inserting an item. Can someone explain what is going on and what I'm need to do to correct it?
I have a grid that is bound via OnNeedDataSource to a table. A second table is bound (in code) to a column, though disabling it still shows the problem. Ultimately I'm trying to select the customer in the combo box to the current item, but if there isn't a customer then to select the first "No Customer" item.
I have a grid that is bound via OnNeedDataSource to a table. A second table is bound (in code) to a column, though disabling it still shows the problem. Ultimately I'm trying to select the customer in the combo box to the current item, but if there isn't a customer then to select the first "No Customer" item.
<
telerik:RadGrid
runat
=
"server"
ID
=
"Test_RadGrid"
AutoGenerateColumns
=
"false"
AllowPaging
=
"true"
OnNeedDataSource
=
"RadGrid_NeedDataSource"
OnUpdateCommand
=
"RadGrid_UpdateCommand"
OnItemCreated
=
"RadGrid_ItemCreated"
OnDeleteCommand
=
"RadGrid_DeleteCommand"
OnInsertCommand
=
"RadGrid_InsertCommand"
OnItemDataBound
=
"RadGrid_ItemDataBound"
>
<
MasterTableView
DataKeyNames
=
"ID"
CommandItemDisplay
=
"Top"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
EditMode
=
"InPlace"
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
/>
<
telerik:GridBoundColumn
DataField
=
"ID"
HeaderText
=
"ID"
ReadOnly
=
"true"
ForceExtractValue
=
"Always"
ConvertEmptyStringToNull
=
"true"
/>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Name"
/>
<
telerik:GridDropDownColumn
UniqueName
=
"CustomerCombo"
HeaderText
=
"Customer"
DropDownControlType
=
"RadComboBox"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
protected
void
RadGrid_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
Test_RadGrid.DataSource = DataSource(); // linq to sql join statement
}
protected
void
RadGrid_ItemDataBound(
object
source, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editableItem = e.Item
as
GridEditableItem;
// ^---- At this point editableItem.KeyValues, in Watch window, says KeyValues threw an exception
// of type System.ArgumentOutOfRangeException, but doesn't break
GridEditManager editManager = editableItem.EditManager
as
GridEditManager;
GridDropDownListColumnEditor editor = editManager.GetColumnEditor(
"CustomerCombo"
)
as
GridDropDownListColumnEditor;
//editor.DataSource = Customer.DataSource();
//editor.DataValueField = TestField.ID;
//editor.DataTextField = TestField.Name;
//editor.DataBind();
RadComboBox combo = editableItem[TestField.CustomerCombo].Controls[0]
as
RadComboBox;
combo.AppendDataBoundItems =
true
;
combo.Items.Insert(0,
new
RadComboBoxItem(
"No customer selected"
,
"0"
));
var ret = (
int
)editableItem.GetDataKeyValue(
"0"
);
// <-- OutOfRangeException thown, debugger
}