I have a gridview control, say, 'grd'. Inside it, I have a template field
<asp:TemplateField>
<ItemTemplate>
<input id="chkSelectRow" type="checkbox" runat="server" name="chkSelectRow" />
</ItemTemplate>
</asp:TemplateField>
if I bind 5 rows in the grid then there will be 5 check boxes. If I have only 2 rows then there will be 2 check boxes. My question is How can I get the id of each check boxe with javascript from an outside event, say, a button click
I think this is what you are looking for :
I have written the Jquery code block which will find your checkboxes form grd
and display it in alert(). you can change code as per your requirement.
HTML for Button :
<input type="button" value="save" onclick="test();" />
Jquery:
function test() {
$('input[type="checkbox"][id*="chkSelectRow"]').each(function () {
alert($(this).attr('id') + ' : ' + $(this).attr('checked'));
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.