如何仅捕获用户更改了值的多行中的那些列? [英] How do I capture only those columns in multiple rows in which user has changed values?

查看:47
本文介绍了如何仅捕获用户更改了值的多行中的那些列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET或JavaScript中,是否有任何方法仅在用户已更新特定列的那些行上运行更新存储过程?

Are there are any approaches in ASP.NET or JavaScript where i run update stored procedure on only those rows in which specific columns have been updated by user?

例如:如果有多行

row1= [column1 column2 column3 column4 coumn 5]
row2= [column1 column2 column3 column4 coumn 5]
row3= [column1 column2 column3 column4 coumn 5]
row4= [column1 column2 column3 column4 coumn 5]

如果在第1行中更新了第2列和第3列,而在第3行中更新了第1列和第4列,我只想捕获这些行和列,并将其作为JSON字符串传递给List,然后我将其转换为DataTable ?

If the column 2 and Column 3 are updated in row 1 and column 1 and column 4 are update in row 3 i want to capture only these rows and columns and pass it as JSON string to List which I am then converting to DataTable?

我应该采取什么方法?

我尝试过的事情:

谷歌搜索了一些样本,但是专家的意见永远是最好的

Googled some samples but an expert opinion is always best

推荐答案

我将对@C Murphy的响应进行一些更新和简化,但是最好在视图模型中设置隐藏字段.我建议您使用复选框,因为默认情况下该复选框为布尔型,并且易于使用其checked属性进行操作.

I'll tack on some updates and simplification to @C Murphy's response, but setting a hidden field in your viewmodel is the best option. I would recommend using a checkbox, as it is boolean by default and easy to manipulate with its checked attribute.

已弃用 keypress事件,并且不会在所有键上触发-特别是 Backspace Delete 键不会触发它,因此有人可以删除字段中的所有内容,并且不会进行任何更新.而是使用keydown事件.这种效果具有相反的效果,因为每个键都会触发它,包括 Shift 和其他可能不会实际更改该字段的键.您可以根据需要验证其他代码中的更改.

The keypress event is deprecated, and doesn't fire on all keys - in particular, the Backspace and Delete keys do not trigger it, so someone could delete everything in a field and no update would occur. Instead, use the keydown event; this has sort of the opposite effect, as every key triggers it, including Shift and other keys that may not actually change the field. You can validate changes in other code if you want to.

我删除了检查每列更改的代码,因为我假设您的更新逻辑要求提供所有对象的数据,或者使用EF可能希望传递整个对象.

I removed the code checking for changes per column, because I assume your update logic asks for all the object's data, or with EF probably expects an entire object to be passed.

剃刀:

// A text field, change PropertyName and add where needed in markup
@Html.TextBoxFor(model => model.itemList[i].PropertyName, new { onkeydown = "markAsChanged(" + i + ")" })

// Hidden checkbox for the IsChanged property
@Html.CheckBoxFor(model => model.itemList[i].PropertyName, new { hidden = "" })

JavaScript:

The Javascript:

// Modern browsers
var markAsChanged = function(i) {
    document.GetElementById('itemList_' + i + '__IsChanged').checked = true;
};

// Use for legacy support with jQuery
var markAsChanged = function(i) {
    $('#itemList_' + i + '__IsChanged').checked = true;
};

如果您想清理视图并省略事件处理程序,则可以添加一些Javascript.

If you wanted to clean up your view and leave out the event handlers, you could add them with some more Javascript.

这篇关于如何仅捕获用户更改了值的多行中的那些列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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