0

我想将我的文本框中写入的值与 gridview 的现有值相匹配。我已经使用以下功能在服务器端完成了此操作

protected void isRecordAlreadyExist(TextBox txt_Value, int res)
{
    ds_main = new DataSet();
    paramArray = new string[3, 2];
    paramArray[0, 0] = "@KeyWinCountNumber";
    paramArray[0, 1] = txtkeyWinCount.Text.Trim();
    paramArray[1, 0] = "@ContractNumber";
    paramArray[1, 1] = txtContractNum.Text.Trim();
    paramArray[2, 0] = "`";
    obj = new DalLib();
    ds_main = obj.getDataSet("sp_tbl_Contract_MatchValues", paramArray);
    gvContract.DataSource = ds_main.Tables[res];
    if (ds_main.Tables[res].Rows.Count > 0)
    {
        mtvResult.ActiveViewIndex = 3;
        btnSubmit.Enabled = false;
    }
    else
    {
        btnSubmit.Enabled = true;
    }
}

protected void txtkeyWinCount_TextChanged(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(txtkeyWinCount.Text))
    {
        isRecordAlreadyExist(txtkeyWinCount, 0);
    }
    else
    {
        mtvResult.ActiveViewIndex = -1;
    }
}

但我也想使用javascript从客户端的gridview数据中匹配文本框的值。我怎样才能做到这一点?任何帮助,将不胜感激。

4

1 回答 1

0

你可以写这样的东西,在网格中搜索 TextBox 值的函数之后,如果找到它返回 true。

您可以在文本框的 onchange javascript 事件上调用此函数

function FindTextBoxValueInGrid
    {
    // Declare the flag
    var flag = false;
    // Get the text we want to compare in the table
    var checkText = document.getElementById('txtkeyWinCount').value;

    // Get the grid
    var gvContract= document.getElementById('gvContract');

    // Loop through each row
    // Starts at row 1 because I assume row 0 is a header row
    for (i=1;i<=gvContract.rows.length;i++)
    {
        var currentRow = gvContract.rows[i];

        if (currentRow.cells[0].value == checkText)
        {
            flag = true;
        }
    }
    return flag;
}
于 2012-09-25T07:25:48.140 回答