NicoRiff
NicoRiff

Reputation: 4883

get value from a gridView from javascript

i have this code in ASP, I need to do the same, but from the client side. I´ve been searching but i couldn´t do the javascript work. I think this would be pretty simple.

    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;        
            }
        }
    }

If you could help me, I would apreciate that. Thanks you!

Upvotes: 2

Views: 8016

Answers (1)

PhilPursglove
PhilPursglove

Reputation: 12589

This is unchecked but it should be something like:

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;
}

Upvotes: 1

Related Questions