2
到GridView的我有使用ObjectDataSource控件實體如何將複雜的實體類型綁定使用的ObjectDataSource
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}
}
現在我結合收集到的GridView。 根據模板列的Person類的部門貌似
<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>
現在我的網格被綁定使用現在
<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>
,當我嘗試更新這個人的實體,它會引發錯誤,因爲下拉顯示值字段和文本字段和Person實體需要一個實際綁定到下拉列表的Dept實體