I've written a class that contains Select- and Update-Methods for an ObjectDataSource. The UpdateMethod receives an instance of a called class. My problem is, that only properties that are Bound in the DetailsView are set, the others have their default value.
Here's my code:
Class declaration:
public class Foo
{
public string Prop1 {get;set:}
public int Prop2 {get;set;}
}
Updatemethod:
[DataObjectMethod(DataObjectMethodType.Update)]
public static void UpdateQuicklink(Foo item)
{
// item.Prop1 // contains correct value
// item.Prop2 // is 0
}
Markup:
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="ods" EnableModelValidation="True" AutoGenerateInsertButton="True"
AutoGenerateRows="False" AutoGenerateEditButton="True">
<Fields>
<asp:BoundField DataField="Prop1"/>
<asp:BoundField DataField="Prop2" Visible="false"/>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="ods" runat="server"
TypeName="NamespaceToClassContaingUpdateMethod"
OldValuesParameterFormatString="original_{0}"
DataObjectTypeName="NamespaceToFoo"
UpdateMethod="UpdateQuicklink">
</asp:ObjectDataSource>
I can't expose every field I need to the markup.
A possible solution would be to rewrite my UpdateMethod to accept all necessary parameters, like that:
[DataObjectMethod(DataObjectMethodType.Update)]
public static void UpdateQuicklink(string Prop1, int Prop2)
{
}
But this solution is crap, due to I it is not flexible enough, if I attempt changes to the underlying datastructure. I know that in that case I'd have to edit my code nevertheless, but I'd to only have my custom wrapper class as parameter. Is that possible?