I have a Telerik RadGrid using an ascx web form user control for editing and adding new records to the grid.
On the web form control I have DropDown setup with this
SelectedValue='<%# DataBinder.Eval(Container, "DataItem.SubjectId_FK") %>'>
And My C# code is this
var SubjectNames = db.T_Subjects.Where(a => a.CaseId_FK == intCaseId).Distinct().ToList();
ddlComparisonSubjects.DataSource = SubjectNames;
//ddlComparisonSubjects.SelectedIndex = -1;
//ddlComparisonSubjects.SelectedValue = null;
The code lines commented out were added while troubleshooting this issue. They did not solve the problem so I commented them out. I have left them so you can see what I have tried to do to fix the problem.
Everything works fine if I am editing an existing record. However when I try to add a new record I get this error message:
'ddlComparisonSubjects' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
I know the Parameter names are correct because the drop down works in edit mode.
So why do these drop downs work in edit mode but not in insert mode and how can I fix it?