0

Hi I am developing the asp.net application with javascript. I have one gridview with checkbox for each row. I have one button below. On clicking upon that button I am displaying values of only checked rows. I am looping through each row of gridview. I am trying as below.

 var second = [];
        $('#<%= gdvRegretletter.ClientID %> input[type="CheckBox"]').each(function () {if($(this).closest('tr').find('input[type="checkbox"]').prop("checked") == true)
            second.push($(this).val());
        });

If there are three checked checkboxes in the gridview I will get three times on on alert. I want to display Name column values. May I get some idean on this or May i know where I am going wrong? Thank you all.

1
  • A word on using this construct: $('#<%= gdvRegretletter.ClientID %>...') It fails if you move the code to it's own JS file. Use an anonymous css class: <asp:GridView id="gdvRegretletter" class="gdvRegretletter" ...> and alter jquery to $('table.gdvRegretletter input[type='checkbox']:checked') Commented Dec 28, 2016 at 17:53

1 Answer 1

1

You can directly get all checked entries like this

var second  = [];
$('#your_id :checked').each(function() {
       second.push($(this).val());
     });
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your response. I hope your_id will be my gridviewID.
be mindful of unintended consequence. The above assumes a single checkbox per row. If you add more checkboxes per row this code will return those as well. It's a good practice to be a specific as you can.

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.