ObjectDataSource 没有插入多个插入参数的值
ObjectDataSource has no values to insert multiple insert params
我有一个 class DocumentRuleViewModel
具有以下函数定义
Insert(ReplaceRule Obj, int DocumentId)
Select(int DocumentId)
Update(ReplaceRule Obj)
Delete(ReplaceRule Obj)
select
、update
和 delete
函数在我的 objectdatasource
上工作得很好,但是 insert
不希望工作并保持告诉我对象是空的
我收到的错误消息是 ObjectDataSource 'dsDocumentSourceRules' has no values to insert. Check that the 'values' dictionary contains values.
有几个类似这样的问题,但是 none 我发现我可以从中找出问题的答案。
我使用的代码如下
<dx:ASPxGridView runat="server" ID="gvDocumentRules"
AutoGenerateColumns="False" DataSourceID="dsDocumentSourceRules" KeyFieldName="ID"
ClientInstanceName="gdDocRules">
<Columns>
<dx:GridViewCommandColumn ShowDeleteButton="True" VisibleIndex="0" ShowNewButtonInHeader="True" ShowEditButton="True">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ID" VisibleIndex="1"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="TypeID" VisibleIndex="2"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="SearchFor" VisibleIndex="3">
</dx:GridViewDataTextColumn><dx:GridViewDataTextColumn FieldName="ReplaceText" VisibleIndex="4"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="OrderIndex" VisibleIndex="5"></dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource runat="server" ID="dsDocumentSourceRules"
DataObjectTypeName="DocumentBuilder.Models.ReplaceRule"
DeleteMethod="Delete"
InsertMethod="Insert"
SelectMethod="RetrieveRulesForDocument"
TypeName="DocumentBuilder.ViewModel.DocumentRuleViewModel"
UpdateMethod="Update">
<InsertParameters>
<asp:Parameter Name="obj" Type="Object"></asp:Parameter>
<asp:ControlParameter ControlID="DocumentTypeIDTextBox" PropertyName="Text" DefaultValue="0" Name="DocumentId" Type="Int32"></asp:ControlParameter>
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DocumentTypeIDTextBox" PropertyName="Text" DefaultValue="0" Name="DocumentId" Type="Int32"></asp:ControlParameter>
</SelectParameters>
</asp:ObjectDataSource>
感谢任何想法或解决方案。我觉得好像缺少一些基本的东西
感谢 DevExpress 团队在其网站上的回复
Thank you for the clarification. According to the answers at
ObjectDataSource has no values to insert, it seems that it is
impossible to pass additional parameters to the Insert method using
this approach. I suggest you use the ObjectDataSource.OnInserting
event handler and invoke the custom Insert method. Do not forget to
set the e.Cancel property to false, otherwise, the method you've
specified in the InsertMethod property will be called. Please refer to
the following code snippet and the attached project.
protected void dsDocumentSourceRules_Inserting(object sender,
ObjectDataSourceMethodEventArgs e) {
ReplaceRule rule = (ReplaceRule)e.InputParameters["obj"];
DocumentRuleViewModel.Insert(rule, Int32.Parse(DocumentTypeIDTextBox.Value.ToString()));
e.Cancel = true; }
...
[DataObjectMethod(DataObjectMethodType.Insert, true)] public static
void Insert(ReplaceRule obj, Int32 DocumentId) {
obj.ID = data.Count;
obj.TypeID = DocumentId;
data.Add(obj); }
我有一个 class DocumentRuleViewModel
具有以下函数定义
Insert(ReplaceRule Obj, int DocumentId)
Select(int DocumentId)
Update(ReplaceRule Obj)
Delete(ReplaceRule Obj)
select
、update
和 delete
函数在我的 objectdatasource
上工作得很好,但是 insert
不希望工作并保持告诉我对象是空的
我收到的错误消息是 ObjectDataSource 'dsDocumentSourceRules' has no values to insert. Check that the 'values' dictionary contains values.
有几个类似这样的问题,但是 none 我发现我可以从中找出问题的答案。
我使用的代码如下
<dx:ASPxGridView runat="server" ID="gvDocumentRules"
AutoGenerateColumns="False" DataSourceID="dsDocumentSourceRules" KeyFieldName="ID"
ClientInstanceName="gdDocRules">
<Columns>
<dx:GridViewCommandColumn ShowDeleteButton="True" VisibleIndex="0" ShowNewButtonInHeader="True" ShowEditButton="True">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ID" VisibleIndex="1"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="TypeID" VisibleIndex="2"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="SearchFor" VisibleIndex="3">
</dx:GridViewDataTextColumn><dx:GridViewDataTextColumn FieldName="ReplaceText" VisibleIndex="4"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="OrderIndex" VisibleIndex="5"></dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource runat="server" ID="dsDocumentSourceRules"
DataObjectTypeName="DocumentBuilder.Models.ReplaceRule"
DeleteMethod="Delete"
InsertMethod="Insert"
SelectMethod="RetrieveRulesForDocument"
TypeName="DocumentBuilder.ViewModel.DocumentRuleViewModel"
UpdateMethod="Update">
<InsertParameters>
<asp:Parameter Name="obj" Type="Object"></asp:Parameter>
<asp:ControlParameter ControlID="DocumentTypeIDTextBox" PropertyName="Text" DefaultValue="0" Name="DocumentId" Type="Int32"></asp:ControlParameter>
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DocumentTypeIDTextBox" PropertyName="Text" DefaultValue="0" Name="DocumentId" Type="Int32"></asp:ControlParameter>
</SelectParameters>
</asp:ObjectDataSource>
感谢任何想法或解决方案。我觉得好像缺少一些基本的东西
感谢 DevExpress 团队在其网站上的回复
Thank you for the clarification. According to the answers at ObjectDataSource has no values to insert, it seems that it is impossible to pass additional parameters to the Insert method using this approach. I suggest you use the ObjectDataSource.OnInserting event handler and invoke the custom Insert method. Do not forget to set the e.Cancel property to false, otherwise, the method you've specified in the InsertMethod property will be called. Please refer to the following code snippet and the attached project.
protected void dsDocumentSourceRules_Inserting(object sender,
ObjectDataSourceMethodEventArgs e) {
ReplaceRule rule = (ReplaceRule)e.InputParameters["obj"];
DocumentRuleViewModel.Insert(rule, Int32.Parse(DocumentTypeIDTextBox.Value.ToString()));
e.Cancel = true; }
...
[DataObjectMethod(DataObjectMethodType.Insert, true)] public static
void Insert(ReplaceRule obj, Int32 DocumentId) {
obj.ID = data.Count;
obj.TypeID = DocumentId;
data.Add(obj); }