I have an entity
class Person
{
public int Age{get;set;}
public string Name{get;set;}
public Department Dept{get;set;}
}
class Department
{
public int DeptId{get;set;}
public string DeptName{get;set}
}
Now I binds Collection to GridView using ObjectDataSource Control. Under the TemplateField for Dept of Person class looks like
<EditItemTemplate>
<asp:DropDownList ID="cmbStatus" DataTextField="DeptName" SelectedValue='<%# Bind("Dept.DeptId") %>'
DataValueField="DeptId" runat="server" CssClass="ddl150px ddlbg"
DataSourceID="deptCollection" />
<asp:ObjectDataSource ID="deptCollection" runat="server"
SelectMethod="GetDeptList" TypeName="LIMS.BusinessObject.Department" >
</asp:ObjectDataSource>
</EditItemTemplate>
Now my Grid gets binded using
<asp:ObjectDataSource ID="PersonCollection" runat="server"
SelectMethod="GetPersonList"
TypeName="LIMS.BusinessObject.Person"
DataObjectTypeName="LIMS.DomainModel.Person"
DeleteMethod="Delete" InsertMethod="Create" UpdateMethod="Update"
ondeleting="PersonCollection_Deleting"
onupdating="PersonCollection_Updating">
</asp:ObjectDataSource>
Now when I tries to update this Person entity, it throws error because dropdown displays Value field and text field and Person entity needs a Dept Entity which is actually binded to dropdownlist