【发布时间】:2011-09-19 20:45:38
【问题描述】:
我有一个实体
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}
}
现在我使用 ObjectDataSource 控件将 Collection 绑定到 GridView。 在 Dept of Person 类的 TemplateField 下看起来像
<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>
现在我的 Grid 使用
绑定了 <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 实体时,它会抛出错误,因为下拉列表显示 Value 字段和文本字段,并且 Person 实体需要一个实际绑定到下拉列表的 Dept 实体
【问题讨论】: