I have a very strange problem I am using a RadGrid with an .ascx user control form to do editing and adding of new records. The form works fine when I am editing a record but crashes when I attempt to add a record.
This is the code used to setup the dropdown on the .ascx page
<
asp:DropDownList
ID
=
"DropDownList1"
runat
=
"server"
DataSourceID
=
"EntityDataSource1"
DataTextField
=
"StatusDescription"
DataValueField
=
"StatusDescription"
SelectedValue='<%# DataBinder.Eval(Container, "DataItem.Status") %>'>
<
asp:ListItem
Selected
=
"True"
Text
=
"Select"
Value
=
""
>
</
asp:ListItem
>
</
asp:DropDownList
>
This is the C# code behind for that page.
namespace
CrimeTips
{
public
partial
class
InvestigationDetailsControl : System.Web.UI.UserControl
{
private
object
_dataItem =
null
;
public
object
DataItem
{
get
{
return
this
._dataItem;
}
set
{
this
._dataItem = value;
}
}
protected
void
DropDownList1_SelectedIndexChanged(
object
sender, DropDownListEventArgs e)
{
string
StatusValue = DropDownList1.DataValueField;
}
}
}
And here is the ASPX code for the EditFormSettings
<
EditFormSettings
UserControlName
=
"InvestigationDetailsControl.ascx"
EditFormType
=
"WebUserControl"
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
>
</
EditColumn
>
</
EditFormSettings
>
The problem is when I edit the data the form works without any issues. However, when I attempt to add a records the application crashes with the yellow screen of death with an error message stating
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
I do not understand why the form works for editing purposes but will not render for the add record can someone offer an explanation and a fix for the problem?
Thanks