简体   繁体   English

如何实现复选框的属性以在不使用Grid对象或jQuery.Data(Input)的情况下跟踪表中每一行的更改?

[英]How to implement properties of checkbox to keep track of your changes on each line in your table without employing Grid object or jQuery.Data(Input)?

在此处输入图片说明

How to perform form requests selectively ONLY on changed lines without involving Grid or jQuery.Data(input) logic? 如何在不涉及Grid或jQuery.Data(input)逻辑的情况下仅在更改的行上选择性地执行表单请求?

Beside the fact that the program is old, AJAX does not apply here because I don't want each line to fire a change event when user enters changes! 除了该程序较旧之外,AJAX不适用于此处,因为我不希望用户输入更改时每一行都触发更改事件! What I want to have is one submit : just 1 click-event from the user after he has finished all the line changes! 我要提交的内容是:用户完成所有行更改后,只需单击1次单击事件!

So, what is the easiest clean-cut way to MINIMIZE the browser-server trips? 那么,最小化浏览器-服务器行程的最简单的捷径是什么?

Each line I have this invisible checkbox 每行我都有这个不可见的复选框

<input type="checkbox" style="display:none;" name="N_CheckChanged">

and other hidden objects on that line to keep track of changes. 和该行上的其他隐藏对象以跟踪更改。

<input type="hidden" value="beforeChangeVal" name="h_CertainObject">

My code on the server-side for changes is 我在服务器端进行更改的代码是

string[] formCheckChanged = Request.Form.GetValues("N_CheckChanged");

However the code can be quite messy if you want to use names derivation (extracting checkbox'es prefix to derive other objects' name) to hash to the objects for their new values to update your db. 但是,如果您要使用名称派生(提取复选框的前缀以获取其他对象的名称)来哈希到对象的新值以更新数据库,则代码可能会很混乱。 And, that's no good. 而且,那不好。

To answer the above question, you have to know 要回答上述问题,您必须知道

Checkbox element has these two distinct attributes 复选框元素具有这两个不同的属性

i. 一世。 checked == true/false 检查==是/否

ii. II。 value := 'any string vals' 值:='任何字符串值'

one not related to the other. 一个与另一个无关。

In your CHECKED attribute, you set it to true only if that line has changes. CHECKED属性中,仅当该行发生更改时,才将其设置为true Checkbox object would make itself invisible (disabled) from Server.Request otherwise . 复选框对象将从Server.Request使自己无形的 (禁用), 否则

In your VALUE attribute, you can stash away all your to-be-posted values for that line(similar to jQuery.Data(input)) disregarding the checked attribute == true/false! VALUE属性中,可以忽略该行的所有待发布值(类似于jQuery.Data(input)),而不必考虑选中的属性== true / false!

Browser on-submit, you execute 提交浏览器后,执行

function do_checkChanges() {// checking each row
    for (var ii = 0; ii < document.getElementsByName("N_CheckChanged").length; ii++) {
        document.getElementsByName("N_CheckChanged")[ii].checked = 0;
    //detect changes
        if ((document.getElementsByName("R_DateResume")[ii].value != document.getElementsByName("h_DateResume")[ii].value)
            || (document.getElementsByName("R_CheckInhibited")[ii].value != document.getElementsByName("h_CheckInhibited")[ii].value)
            )
        {
            document.getElementsByName("N_CheckChanged")[ii].checked = 1;//mark the change
            document.getElementsByName("N_CheckChanged")[ii].value =
                document.getElementsByName("h_RowID")[ii].value + "|"
                + document.getElementsByName("R_CheckInhibited")[ii].checked + "|"
                + document.getElementsByName("R_DateResume")[ii].value
            ;
        }
    }
    whoPostBack.value = 'view2';
}

After you have stored your updates inside the checkboxes, your server-side code should be like a breeezzee! 将更新存储在复选框中之后,服务器端代码应像微风一样! On the server side, all you need to do is 在服务器端,您所需要做的就是

string[] formCheckChanged = Request.Form.GetValues("N_CheckChanged");
if (formCheckChanged != null)
{
    foreach (string checkChanged in formCheckChanged)
    {
        sValues = checkChanged.Split('|');
        correspondedRow = sValues[0];
        data1 = sValues[1];
        data2 = sValues[2];
        theSqlCmd.CommandText =
            " update tb_LOG set InhibitedNow='" + data1 + "', InhibitEnd = '" + data2 + "', InhibitedBy = '" + MyConnections.userID
            + "' where RowID =" + correspondedRow;
        try
        {
            theSqlCmd.ExecuteNonQuery();
        }
        catch (Exception eX)
        {
            Response.Write(theSqlCmd.CommandText); Response.End();
        }
    }
    //Response.End();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM