从javascript中获取gridView的值

时间:2011-08-23 14:03:48

标签: javascript asp.net

我在ASP中有这个代码,我需要做同样的事情,但是从客户端来看。我一直在搜索,但我不能做javascript工作。我认为这很简单。

    protected void btnProbar_Click(object sender, EventArgs e)
    {
        bool flag = false;

        foreach(GridViewRow c in grdDatos.Rows)
        {
            if (c.Cells[0].Text == txtNroUnidad.Text)
            {
                flag = true;        
            }
        }
    }

如果你能帮助我,我会赞成这一点。谢谢你!

1 个答案:

答案 0 :(得分:1)

这是未选中,但它应该是:

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

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

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

        if (currentRow.cells[0].value == checkText)
        {
            flag = true;
        }
    }

    return flag;
}