Problem inserting data with the GenericObjectDataSourse

Jun 26, 2010 at 5:18 PM

Hi. 

I am using the GenericObjectDataSource with a FormView control. The form view is using ItemTemplate, InsertItemTemplate and UpdateItemTemplate. Loading the data in the form view is working good. But here is my problem. I'm trying to insert the data entered in the text boxes, but I got exception "ObjectDataSource 'godsCourses' has no values to insert. Check that the 'values' dictionary contains values." I also check the values passed to the OnItemInserting event handler of the form view, but the list is empty. I would appreciate if you can help me solving this and here is my code:

 

	<asp:Panel ID="pnlGeneralInfo" runat="server">
		<fieldset>
			<legend>General Information</legend>
			<div class="twoCol">
				<asp:FormView ID="fvCourses" runat="server" DataSourceID="godsCourses" Width="100%" oniteminserting="fvCourses_ItemInserting" DataKeyNames="ID" >
					<ItemTemplate>
						<asp:Label ID="lblName" runat="server" Text="Name" />
						<asp:Label ID="lblNameField" runat="server" Text='<%# Eval("Name") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCode" runat="server" Text="Code" />
						<asp:Label ID="lblCodeField" runat="server" Text='<%# Eval("Code") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCredits" runat="server" Text="Credits" />
						<asp:Label ID="lblCreditFields" runat="server" Text='<%# Eval("Credits") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCourseType" runat="server" Text="Course Type" />
						<asp:Label ID="ddlCourseType" runat="server" Text='<%# Eval("CourseType.Name") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblIsActive" runat="server" Text="Is Active" />
						<asp:CheckBox ID="cbIsActive" runat="server" Text="" Enabled="false" />
						<div class="clear">
						</div>
					</ItemTemplate>
					<InsertItemTemplate>
						<asp:Label ID="lblName" runat="server" Text="Name *" />
						<asp:TextBox ID="txtName" runat="server" CssClass="input" Text='<%# Eval("Name") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCode" runat="server" Text="Code *" />
						<asp:TextBox ID="txtCode" runat="server" CssClass="input" Text='<%# Eval("Code") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCredits" runat="server" Text="Credits *" />
						<asp:TextBox ID="txtCredits" runat="server" CssClass="input" Text='<%# Eval("Credits") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCourseType" runat="server" Text="Course Type *" />
						<asp:DropDownList ID="ddlCourseType" runat="server" DataTextField="Name" DataValueField="ID" DataSourceID="godsCourseTypes" />
						<div class="clear">
						</div>
						<asp:Label ID="lblIsActive" runat="server" Text="Is Active *" />
						<asp:CheckBox ID="cbIsActive" runat="server" Text="" />
						<div class="clear">
						</div>
						<asp:Button ID="btnSaveNew" runat="server" Text="Save" CommandName="Insert"/>
					</InsertItemTemplate>
					<EditItemTemplate>
						<asp:Label ID="lblName" runat="server" Text="Name *" />
						<asp:TextBox ID="txtName" runat="server" CssClass="input" Text='<%# Eval("Name") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCode" runat="server" Text="Code *" />
						<asp:TextBox ID="txtCode" runat="server" CssClass="input" Text='<%# Eval("Code") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCredits" runat="server" Text="Credits *" />
						<asp:TextBox ID="txtCredits" runat="server" CssClass="input" Text='<%# Eval("Credits") %>' />
						<div class="clear">
						</div>
						<asp:Label ID="lblCourseType" runat="server" Text="Course Type *" />
						<asp:DropDownList ID="ddlCourseType" runat="server" DataTextField="Name" DataValueField="ID" DataSourceID="godsCourseTypes" />
						<div class="clear">
						</div>
						<asp:Label ID="lblIsActive" runat="server" Text="Is Active *" />
						<asp:CheckBox ID="cbIsActive" runat="server" Text="" />
						<div class="clear">
						</div>
					</EditItemTemplate>
				</asp:FormView>
			</div>
		</fieldset>
	</asp:Panel>
	<cc1:GenericObjectDataSource ID="godsCourses" runat="server" OldValuesParameterFormatString="original_{0}" DataObjectTypeName="MyCourses.DataAccess.Course" TypeName="MyCourses.DataAccess.CourseStaticRepository"
		SelectCountMethod="Count" SelectMethod="GetEntity" UpdateMethod="Update" DeleteMethod="Delete" InsertMethod="Insert" OnUpdating="godsCourses_Updating" OnInserting="godsCourses_Inserting">
		<SelectParameters>
			<asp:QueryStringParameter Name="id" QueryStringField="ID" Type="Object" DefaultValue="1" />
		</SelectParameters>
		<UpdateParameters>
			<asp:ControlParameter Name="Name" PropertyName="Name" ControlID="txtName" />
			<asp:ControlParameter Name="Code" PropertyName="Code" ControlID="txtCode" />
			<asp:ControlParameter Name="Credits" PropertyName="Credits" ControlID="txtCredits" />
		</UpdateParameters>
		<InsertParameters>
		        <asp:Parameter Name="entity" Type="Object"/>
                	<asp:Parameter DefaultValue="true" Name="submitChanges" Type="Boolean"/>
		</InsertParameters>
	</cc1:GenericObjectDataSource>

Jun 26, 2010 at 9:09 PM

I managed to solve the problem. I didn't noticed that I was using Eval except Bind method. So, the data source couldn't know which are the parameters.