Gridview header check box selection is always false in asp.net(populated using jquery ajax) -
on button click have populated grid view using jquery ajax using below code.
$(document).ready(function () { $("#btnshowdata").click(function () { $('#gvdata').empty(); load_data(0, 30); }); }); function load_data(ipageindex, ipagesize) { $.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: "gridajaxdotnetspan.aspx/bindemployees", data: json.stringify({ ipageindex: ipageindex, ipagesize: ipagesize }), datatype: "json", success: function (result) { $('#gvdata').empty(); $('#gvdata').append("<tr><th><input type='checkbox' id='chkorgheader' name='chkorgheader' onclick='selectall();' /></th><th>empid </th><th>empname </th><th>empsal </th><th>empaddr </th></tr>") (var = 0; < result.d.length; i++) { $("#gvdata").append("<tr><td><input type='checkbox' id='chkorgrow' name='chkorgrow' /></td><td>" + result.d[i].empid + "</td><td>" + result.d[i].empname + "</td><td>" + result.d[i].empsal + "</td><td>" + result.d[i].empaddr + "</td></tr>"); } hideorshownavigation(); }, error: function (result) { alert("error"); } }); }
and on selection of header check box want select child checkboxes. have used below code.
function selectall() { var bool = $("#gvdatainput[id*='chkorgheader']:checkbox").is(':checked'); //var ischecked = $(checked).attr('checked') ? true : false; //tired on passing "this" chkorgheader onclick="selectall(this)" if (bool) { $('input:checkbox[name$=chkorgrow]').each( function () { $(this).attr('checked', 'checked'); }); } else { $('input:checkbox[name$=chkorgrow]').each( function () { $(this).removeattr('checked'); }); } }//end of select
the above selectall function getting fired when select header checkbox "chkorgheader" getting checked false.
am going in right direction? please suggest me how achieve requirement.
i need below points: 1. when select header check box, child checkboxes should select
- when select particular child check box want find out empsal field value
point 1 - below code not select checkbox
because of improper selector
. need give space between id #gvdata
, input
, don't need *
id
+ no need filter :checkbox
selecting checkbox id
unique. modify code below:
var bool = $("#gvdata input[id='chkorgheader']").is(':checked');
you might face issue .attr
suggest use .prop
instead
demo .prop
//works fine
$(this).prop('checked', true); //check checkbox $(this).attr('checked',false);//uncheck checkbox
demo .attr
//checks , unchecks first time , unfunctional
point 2
since adding checkboxes
dynamically can use below jquery
eventlistener perform action value
$(document).on('change','td input[type="checkbox"]',function(){ if($(this).prop('checked')) alert($(this).parent('td').siblings('td:nth-child(4)').text()); //you can either store in variable per needs ^^^^^^^retrieves values of column 4 salary });
Comments
Post a Comment