ObjectDataSource Gridview Insert Fails W/ Empty Values Dictionary

强颜欢笑 提交于 2019-12-03 16:43:19

Your example isn't consistent since you have DataObjectTypeName set, but your LeasesDS_Inserting method is adding parameters as if it's not.

If you don't need DataObjectTypeName, you can remove it and then you should have a better chance getting this to work.

If you need DataObjectTypeName or just prefer it (as I do), there is a way to get this to work, but it's not pretty.

In your LeasesGrid_RowCommand method, you can use code like this to get the view:

IDataSource ds = (IDataSource)LeasesDS;
DataSourceView view = ds.GetView(LeasesGrid.DataMember);

After getting the view, you can build a dictionary containing the values that need to get written to the data object that will eventually get passed in to your Insert method. The code for that will look very similar to what you have in LeasesDS_Inserting, but you'll be inserting into your own dictionary instead of e.InputParameters.

Once you have your dictionary ready, you can invoke Insert on the view with something like this:

view.Insert(dict, delegate { return false; });

That should do it.

You won't need the LeasesDS_Inserting method any more since the view's Insert method will do the work of converting the dictionary you gave it into the data object that it's going to pass in to your Insert method.

If you need to do more processing of the properties on that data object, you will see it in the InputParameters dictionary passed in to LeasesDS_Inserting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!