从Gridview删除行后,将其从数据库aso.net csharp中删除 [英] Delete row from Gridview later delete it from database aso.net csharp

查看:77
本文介绍了从Gridview删除行后,将其从数据库aso.net csharp中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用与数据库绑定的gridview以及数据库,gridview正在从数据库中提取数据并能够添加新行并删除现有行。现在我的观点是,我如何在数据表中保存已删除的行,并在保存按钮上将其从数据库中删除。

任何帮助都是非常有用的。

I am using a gridview which is bind with datatable as well with database, gridview is pulling data from database and ability to add new row and delete the exisiting row. now my point is that how can i save that deleted row in datatable and on save button delete it from database as well .
Any help is much appericated.

推荐答案

嗨Mer Yasio Basio。



有两种方法,



一种方法是使用临时数据表,并通过在列中设置删除标记将已删除的行标记为已删除。稍后当用户保存页面/网格时,根据'已删除'标志处理数据表。



其他是隐藏字段(名称类似于'hdnDeletedRow')绑定网格时的每一行。因此,当用户单击特定行的删除按钮时,更新隐藏字段的值。因此,当您保存页面/网格时,添加一个检查,如果hdnDeletedRow.value为零,则保存该行,否则忽略/删除该行。



建议:第二种方法只需很少的努力就可以获得更好的性能。
hi Mer Yasio Basio.

There are two ways to do that,

One is to use a temporary datatable and mark the deleted row as 'Deleted' by setting a delete flag in a column. Later when user save the page/grid, process the datatable according to 'Deleted' flag.

Other is take a hidden field (name is like 'hdnDeletedRow') with each row while binding the grid. So when user click the delete button for particular row, update the value of hidden field. SO when you save the page/grid, add an check if hdnDeletedRow.value is zero then save the row else ignore/delete the row.

Suggestion : The 2nd approach will results better performance with little efforts.


你必须在 Session DataTable c $ c>或 ViewState 。然后在删除时,从会话 ViewState 中删除​​。



在更新到数据库时,从会话中获取 DataTable ViewState
You have to store the DataTable either in Session or ViewState. Then while deleting, delete from Session or ViewState.

While updating to Database, take DataTable from Session or ViewState.


这篇关于从Gridview删除行后,将其从数据库aso.net csharp中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆