0

I am doing validation for gridview on button click.

My requirement is in gridview I can add multiple rows at a time. Suppose if I add 2 rows, In any of 2 rows there should be atleast a column with value PURCHASER then it satisfies my requirement.

But if in both rows there is not PURCHASER then it should prompt alert.

So what I wrote is

for (i = 0; i < GrdPartyInfo.Rows.length; i++) {
            if (GrdPartyInfo.Rows[i].Cells[3].Value != "PURCHASER") {
                alert('There should be atleast one purchaser');
                return false;
            }    
        }

But what happens is, if I add PURCHASER in second row it still prompts me error. WHY ?

1 Answer 1

1

You are just checking the first value, and if it is not a purchaser, you output the error, ignoring other values. Instead this should be:

var hasPurchaser = false;
for (i = 0; i < GrdPartyInfo.Rows.length; i++) {
    if (GrdPartyInfo.Rows[i].Cells[3].Value == "PURCHASER") {
        hasPurchaser = true;
    }    
}

if (!hasPurchaser) {
    alert('There should be at least one purchaser');
    return false;
}
Sign up to request clarification or add additional context in comments.

2 Comments

let me try and check this one.!
yes it is working fine..will accept after checking througly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.