Я решил проблему:
Проблема заключалась в том, что схема Project
и схема ProjectOverall
не совпадали.
Я изменил адаптер и добавил метод доступа для ProjectOverall
.
SELECT ID, CountryID, OrganisationUnitID, ProjectYear, ProjectName
FROM wc_ProjectsOverall
WHERE (CountryID = @CountryID) AND (OrganisationUnitID = @OrganisationUnitID) AND (ProjectYear = @ProjectYear)
В ProjectOverall.cs
:
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.ProjectsOverallDataTable GetProjectsOverallByAttributes(Guid CountryID, Guid OrganisationUnitID, Int32 ProjectYear)
{
if (CountryID == null || OrganisationUnitID == null || ProjectYear == 0)
return new WebControlling.ProjectsOverallDataTable();
return Adapter.GetProjectsByAttribute(CountryID, OrganisationUnitID, ProjectYear);
}
В представлении ProjectAdd.aspx
:
<asp:TemplateField HeaderText="Project">
<InsertItemTemplate>
<asp:DropDownList ID="lstProjectOverall" Width="250px" runat="server" DataTextField="ProjectName" DataSourceID="ObjectDataSourcePOs" DataValueField="ID" AppendDataBoundItems="False"></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:ObjectDataSource ID="ObjectDataSourceProject" runat="server" InsertMethod="AddProject" OldValuesParameterFormatString="{0}" SelectMethod="GetProjects" TypeName="Projects" OnInserting="ObjectDataSourceProject_Inserting" >
<InsertParameters>
<asp:Parameter Name="CountryID" Type="Object" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Objective" Type="String" />
<asp:Parameter Name="ObjectiveQuantitativ" Type="String"/>
<asp:Parameter Name="ProjectYear" Type="Int32" />
<asp:Parameter Name="BaseCampaign" Type="Boolean" />
<asp:Parameter Name="ManagerID" Type="Object" />
<asp:Parameter Name="OrganisationUnitID" Type="Object" />
<%-- This parameter is different because the ProjectOverall ID is not part of the Project model, thus we insert the DropDownList value --%>
<asp:ControlParameter ControlID="DetailsViewProject$lstProjectOverall" name="ID" PropertyName="SelectedValue"/>
</InsertParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSourcePOs" runat="server"
SelectMethod="GetProjectsOverallByAttributes" TypeName="ProjectsOverall">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsViewProject$lstProjectYears" name="ProjectYear" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DetailsViewProject$lstOEs" name="OrganisationUnitID" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DetailsViewProject$lstCountries" name="CountryID" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:ObjectDataSource>
И это решило мою проблему.