0

环境:asp.net fx3.5

我正在为我的gridview 使用objectdatasource。起初,我List<Attachments>为我的客户加载了来自通用记录的 gridview。接下来,我想在所有添加/删除完成之前,在不访问数据库的情况下从 gridview 添加/删除项目。然后用户将点击保存按钮,然后我将在 gridview 中保留项目。

我的问题是如何在 objectdatasource 连接到 gridview 时在 gridview 中添加/删除项目?我的猜测是以某种方式将 gridview 行转换回通用列表,然后添加/删除项目,然后重新绑定?这甚至可能吗?

4

3 回答 3

1

I would recommend to save changes to database if you are doing or can do postback on add/remove. As not saving data along change might cause loss of information. You can use ajax call for add/remove to make it more elegant and fast without reloading whole page.

or

If you want to do all add/remove on client side and finally saving to database, you can uses client storage to keep the changes temporarily and finally sending the changes back to server and commit them to database. Article about client storage here but it might not be supported by old browsers

or

You can put change in hidden fields e.g for deleted records you have one hidden field which store deleted record ids, on hidden field with added records with set pattern and update the database on postback using these hidden fields again there is hazard for losing information with this method

于 2012-05-21T15:41:58.030 回答
1

您可以暂时存储在 ViewState 中。您需要有一个提供者类,即对您存储在视图状态中的列表执行基本 CRUD 操作的类。

于 2012-05-21T17:07:42.873 回答
0

由于您将只使用网格事件来存储所有这些信息以进行处理,因此您在数据源中唯一需要的是一个 select 方法,这样它就不会尝试更新/插入记录。您可以对 rowCommand 事件进行所有事件处理。

至于你正在尝试什么,我认为这不是一个好主意。您将不得不跟踪会话中的多条记录,或单独的数据库表(但那有什么意义呢?)。

于 2012-05-21T15:32:45.237 回答