【问题标题】:how to get the new entered value in gridview in javascript如何在javascript中的gridview中获取新输入的值
【发布时间】:2018-01-22 07:54:02
【问题描述】:

我正在处理一个项目并使用网格视图来查看一些可编辑的数据。我对这些数据有一些限制,我想在数据发送到数据库之前执行前端检查。我的代码如下:

<asp:Button ID="Update" runat="server" CausesValidation="True" 
            CommandName="Update" Text="Update" onclientClick="check(this)"/>

而我的 JavaScript 如下:

function check(up) {

    var ip, desc, rt;

    var table = document.getElementById('<%=GridView1.ClientID %>');

    var row = up.parentNode.parentNode;

    ip = row.cells[1].children[0].attributes[2].value;
    desc = row.cells[2].children[0].attributes[2].value;
    rt = row.cells[3].children[0].attributes[2].value;
    time = parseFloat(rt);
    alert(rt);

    if (ip === null || ip.match(/^ *$/) !== null) {
        alert('please enter IP Address');
        return false;
    }
    else if (desc === null || desc.match(/^ *$/) !== null) {
        alert('please enter description');
        return false;
    }
    else if (rt === null || rt.match(/^ *$/) !== null) {
        alert('please enter refresh time');
        return false;
    }
    else if (isNaN(time)){
        alert('refresh time must be a number');
        return false;
    }
    else if (Number(time) < 1) {
        alert('the minimum refresh time is 1');
        return false;
    }
    else 
        return true;
}

问题是我总是得到旧值而不是新值。如何在 JavaScript 中获取新值? 我在更新查询中使用sqlDataSource

UPDATE Clients
SET ipAddress = @ipAddress, description = @description, refreshTime = @refreshTime
WHERE machineName = @MachineName

【问题讨论】:

    标签: javascript c# asp.net gridview


    【解决方案1】:

    你没有从你的行获取行索引,试试这个:

    var table = document.getElementById('<%=GridView1.ClientID %>');
    
    var row = up.parentNode.parentNode;
    
    var rindex = row.rowIndex; // get gridview row index
    
    ip = table.rows[rindex].cells[1].children[0].value;
    desc = table.rows[rindex].cells[2].children[0].value;
    rt = table.rows[rindex].cells[3].children[0].value;
    

    【讨论】:

      猜你喜欢
      • 2017-11-02
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多