1

Hi I am developing one application using asp.net and jquery where i have one gridview. I am trying to hide rows of grid view based on certain condition. I tried with some jquery code as below.

for (var k = 0; k < result.length; k++)
            {
                $('#<%= GridView1.ClientID %> input[type="hidden"]').each(function () {

                    if($(this).val()==result[k])
                    {

                      //Want to hide kth row of gridview 
                    }
                });

            }

And as soon as i hide the row then i want to break the inner loop. I tried by putting break but it is not working. May I have some inputs on the above problem? Thank you.

1 Answer 1

3

Yo need to fetch the parent row in which hidden filed lies and hide it.

 $('#<%= GridView1.ClientID %> input[type="hidden"]').each(function () {

    if($(this).val()==result[k])
    {

      //$(this).closest('tr').css('display','none');
      $(this).closest('tr').find('input[type="checkbox"]').prop('disabled',true);
      return false;
    }
  });

closest() function searches up the DOM tree i.e selected element's ancestor and return false is used to break out of each() function.

Sign up to request clarification or add additional context in comments.

3 Comments

I am struggling for this piece of code from past week. This is working like charm. Thank you... I am new to this asp.net world. again thank you very much
Sorry for asking again doubts. Suppose if i have checkbox in that row and instead of removing entire row just if i want to disable that checkbox then what I would have to do?
I tried as below. $(this).closest("td").find("input:CheckBox").attr("checked", false); But still i am able to check and uncheck checkbox.

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.